-
Notifications
You must be signed in to change notification settings - Fork 0
Improve performance of the client #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jkanche
wants to merge
4
commits into
master
Choose a base branch
from
perf
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| name: Build documentation | ||
|
|
||
| on: | ||
| push: | ||
| tags: | ||
| - "*" | ||
|
|
||
| jobs: | ||
| test: | ||
| name: Build docs | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Python 3.12 | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: 3.12 | ||
| cache: 'pip' | ||
|
|
||
| - name: Install Python dependencies | ||
| run: | | ||
| python -m pip install --upgrade pip setuptools | ||
| pip install cmake pybind11 numpy tox lz4 | ||
|
|
||
| - name: Build docs | ||
| run: | | ||
| python setup.py build_ext --inplace | ||
| cp build/lib*/wobbegong/lib_wobbegong* src/wobbegong/ | ||
| tox -e docs | ||
| touch ./docs/_build/html/.nojekyll | ||
|
|
||
| - name: GH Pages Deployment | ||
| if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/') | ||
| uses: JamesIves/github-pages-deploy-action@v4 | ||
| with: | ||
| branch: gh-pages # The branch the action should deploy to. | ||
| folder: ./docs/_build/html | ||
| clean: true # Automatically remove deleted files from the deploy branch | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| cmake_minimum_required(VERSION 3.24) | ||
|
|
||
| project(wobbegong | ||
| VERSION 1.0.0 | ||
| DESCRIPTION "Building the wobbegong cpp library" | ||
| LANGUAGES CXX) | ||
|
|
||
| include(FetchContent) | ||
|
|
||
| FetchContent_Declare( | ||
| lz4 | ||
| GIT_REPOSITORY https://github.com/lz4/lz4.git | ||
| GIT_TAG v1.10.0 | ||
| SOURCE_SUBDIR build/cmake | ||
| ) | ||
|
|
||
| set(LZ4_BUILD_LEGACY_LZ4C OFF CACHE BOOL "" FORCE) | ||
| set(LZ4_BUILD_CLI OFF CACHE BOOL "" FORCE) | ||
| set(CMAKE_POSITION_INDEPENDENT_CODE ON) | ||
|
|
||
| FetchContent_MakeAvailable(lz4) | ||
|
|
||
| find_package(pybind11 CONFIG) | ||
|
|
||
| pybind11_add_module(wobbegong | ||
| src/reader.cpp | ||
| ) | ||
|
|
||
| set_property(TARGET wobbegong PROPERTY CXX_STANDARD 17) | ||
|
|
||
| find_package(ZLIB REQUIRED) | ||
|
|
||
| target_link_libraries(wobbegong PRIVATE lz4_static pybind11::pybind11 ZLIB::ZLIB) | ||
|
|
||
| # Ensure the output name matches what Python expects | ||
| set_target_properties(wobbegong PROPERTIES | ||
| OUTPUT_NAME lib_wobbegong | ||
| PREFIX "" | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| #include <pybind11/pybind11.h> | ||
| #include <pybind11/numpy.h> | ||
| #include <pybind11/stl.h> | ||
| #include <vector> | ||
| #include <string> | ||
| #include <thread> | ||
| #include <future> | ||
| #include <algorithm> | ||
| #include <numeric> | ||
| #include <iostream> | ||
| #include <cstring> | ||
|
|
||
| #include <zlib.h> | ||
| #include <lz4.h> | ||
| #include <sys/mman.h> | ||
| #include <sys/stat.h> | ||
| #include <fcntl.h> | ||
| #include <unistd.h> | ||
|
|
||
| namespace py = pybind11; | ||
|
|
||
| class MMapFile { | ||
| public: | ||
| const char* data = nullptr; | ||
| size_t size = 0; | ||
| int fd = -1; | ||
|
|
||
| MMapFile(const std::string& path) { | ||
| fd = open(path.c_str(), O_RDONLY); | ||
| if (fd == -1) throw std::runtime_error("Could not open file: " + path); | ||
|
|
||
| struct stat sb; | ||
| if (fstat(fd, &sb) == -1) throw std::runtime_error("fstat failed"); | ||
| size = sb.st_size; | ||
|
|
||
| if (size > 0) { | ||
| data = (const char*)mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0); | ||
| if (data == MAP_FAILED) throw std::runtime_error("mmap failed"); | ||
| } | ||
| } | ||
|
|
||
| ~MMapFile() { | ||
| if (data && size > 0) munmap((void*)data, size); | ||
| if (fd != -1) close(fd); | ||
| } | ||
| }; | ||
|
|
||
| size_t decompress_block(const char* src, size_t src_size, std::vector<char>& dst, const std::string& algo) { | ||
| if (src_size == 0) return 0; | ||
|
|
||
| if (dst.empty()) dst.resize(std::max((size_t)1024, src_size * 4)); | ||
|
|
||
| while (true) { | ||
| if (algo == "lz4") { | ||
| int res = LZ4_decompress_safe(src, dst.data(), static_cast<int>(src_size), static_cast<int>(dst.size())); | ||
| if (res >= 0) return static_cast<size_t>(res); | ||
| dst.resize(dst.size() * 2); | ||
| } else { | ||
| uLongf dLen = dst.size(); | ||
| int res = uncompress(reinterpret_cast<Bytef*>(dst.data()), &dLen, reinterpret_cast<const Bytef*>(src), src_size); | ||
|
|
||
| if (res == Z_OK) return dLen; | ||
| if (res == Z_BUF_ERROR) { | ||
| dst.resize(dst.size() * 2); | ||
| } else { | ||
| throw std::runtime_error("Zlib decompression failed with error code: " + std::to_string(res)); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| py::bytes decompress_wrapper(py::bytes src_bytes, const std::string& compression) { | ||
| std::string src_str = src_bytes; | ||
| std::vector<char> dst; | ||
|
|
||
| size_t out_size; | ||
|
|
||
| { | ||
| py::gil_scoped_release release; | ||
| out_size = decompress_block( | ||
| src_str.data(), | ||
| src_str.size(), | ||
| dst, | ||
| compression | ||
| ); | ||
| } | ||
|
|
||
| return py::bytes(dst.data(), out_size); | ||
| } | ||
|
|
||
| PYBIND11_MODULE(lib_wobbegong, m) { | ||
| m.doc() = "Wobbegong high-performance C++ reader/writer bindings"; | ||
|
|
||
| m.def( | ||
| "decompress", | ||
| &decompress_wrapper, | ||
| py::arg("data"), | ||
| py::arg("compression") = "zlib", | ||
| R"pbdoc( | ||
| Decompress a compressed byte buffer. | ||
|
|
||
| Args: | ||
| data: | ||
| Compressed data buffer. | ||
|
|
||
| compression: | ||
| Compression algorithm ("zlib" or "lz4"). | ||
|
|
||
| Returns: | ||
| Decompressed data. | ||
| )pbdoc" | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.