{"id":19674018,"url":"https://github.com/robaho/cpp_leveldb","last_synced_at":"2025-11-21T22:02:53.135Z","repository":{"id":241638874,"uuid":"807316570","full_name":"robaho/cpp_leveldb","owner":"robaho","description":"A port of the ultra-high-performance robaho key-value database using modern C++.","archived":false,"fork":false,"pushed_at":"2025-02-12T23:34:22.000Z","size":307,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-27T05:33:11.694Z","etag":null,"topics":["cpp","database","key-value-database","key-value-store","leveldb","lsm-tree"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/robaho.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-05-28T21:43:50.000Z","updated_at":"2025-02-12T23:34:26.000Z","dependencies_parsed_at":"2025-02-27T05:29:59.274Z","dependency_job_id":"669fcba3-6726-46fb-9a22-7aa6b8ee5505","html_url":"https://github.com/robaho/cpp_leveldb","commit_stats":null,"previous_names":["robaho/cpp_leveldb"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/robaho/cpp_leveldb","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robaho%2Fcpp_leveldb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robaho%2Fcpp_leveldb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robaho%2Fcpp_leveldb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robaho%2Fcpp_leveldb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/robaho","download_url":"https://codeload.github.com/robaho/cpp_leveldb/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robaho%2Fcpp_leveldb/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":285697828,"owners_count":27216628,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-11-21T02:00:06.175Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpp","database","key-value-database","key-value-store","leveldb","lsm-tree"],"created_at":"2024-11-11T17:16:59.965Z","updated_at":"2025-11-21T22:02:53.117Z","avatar_url":"https://github.com/robaho.png","language":"C++","readme":"## summary\n\nThis is a C++ port of my ultra low-latency [keydb](https://github.com/robaho/leveldb) key/value database.\n\n## background\n\nThe main motivation for this project was to familiarize myself with current C++ development, specifically C++20.\n\nThe project is a bit of an \"inception\", in that, my original keydb was written in Go, then I did a Java port, then I discovered the Google [leveldb](https://github.com/google/leveldb/tree/068d5ee1a3ac40dabd00d211d5013af44be55bea) project - which is written in C++. I changed the keydb api to mimic the Google leveldb api - and renamed them leveldb and jleveldb.\n\nNow with this C++ port, I have written the same library from scratch in three languages ([Java code](https://github.com/robaho/jleveldb),[Go code](https://github.com/robaho/leveldb))- along with an independent version developed by Google. My library focus was on api simplicity, maintainability and performance. The three versions are written using the same design, but are idiomatic within the language.\n\nleveldb only supports multi-threaded access. There is a client/server module to expose cpp_leveldb for multi-process access available at [cpp_leveldbr](https://github.com/robaho/cpp_leveldbr)\n\n## performance\n\nGoogle's leveldb includes a benchmarking tool [dbbench](https://github.com/google/leveldb/blob/068d5ee1a3ac40dabd00d211d5013af44be55bea/benchmarks/db_bench.cc). I have replicated this in each of the libraries. All tests are run on the same Intel iMac under OSX. All timings are in microseconds / operation. The methodology is that for each platform, db_bench was run multiple times, and the lowest timing for each task was recorded. Because of the short duration of the test, and the tasks themselves, they are subject to OS background interference.\n\n| Test | [Go](https://github.com/robaho/leveldb)     | Go PGO\u003csup\u003e2\u003c/sup\u003e | [Java](https://github.com/robaho/jleveldb) | Java GraalVM\u003csup\u003e1\u003c/sup\u003e | C++ | C++ PGO\u003csup\u003e2\u003c/sup\u003e | [Google](https://github.com/google/leveldb/tree/068d5ee1a3ac40dabd00d211d5013af44be55bea) |\n| --- | ---: | ---: |---: | ---: | ---: | ---: | ---: |\n| write no-sync | 4.25 | 4.23 |4.86 | 5.51 | 4.65 | 4.36 | 4.60 |\n| write sync\u003csup\u003e3\u003c/sup\u003e | 45 | 46 | 46 | 50 | 10822 | 10888 | 10023 |\n| write batch | 1.07 | 1.06 | 1.06 | 1.72 | 1.19 | 1.02 | 1.94 |\n| write overwrite | 4.37 | 4.30 | 4.65 | 5.60 | 4.65 | 4.43 | 8.20 |\n| read random | 2.44 | 2.49 | 3.79 | 8.07 | 5.93 | 4.61 | 4.74 |\n| read sequential | 0.36 | 0.31 | 0.35 | 0.51 | 0.53 | 0.42 | 0.15 |\n| read random compact | 2.44 | 2.40 | 3.62 | 7.55 | 3.71 | 2.68 | 2.13 |\n| read sequential compact | 0.09 | 0.09 | 0.07 | 0.14 | 0.06 | 0.04 | 0.12 |\n\n\u003csup\u003e1\u003c/sup\u003e Profile guided optimizations are not enabled since they require the enterprise version.\n\n\u003csup\u003e2\u003c/sup\u003e Compiled with profile guided optimizations.\n\n\u003csup\u003e3\u003c/sup\u003e Both C++ and Google versions use `FULLFSYNC` on OSX for improved safety.\n\n## learnings\n\nModern C++ is a joy in many ways but it isn't perfect.\n\n### pros\n\n1. Approaches garbage collection memory safety by using `shared_ptr`, `unique_ptr`, etc.\n1. Tools like ASan make tracking down memory issues/leaks fairly straightforward.\n1. Many easy to use profilers available. I used [Samply](https://github.com/mstange/samply) during development.\n1. Many modern debuggers and IDEs available - supporting syntax highlighting, code completion and popup api documentation.\n1. Excellent support for unit tests using facilities like Boost.\n1. Performance can be outstanding.\n\n### cons\n\n1. `shared_ptr` is slow, making it only suitable for top-level objects, then you must use raw pointers internally.\n1. Dynamic memory management (e.g. `malloc/free`) is very slow. This necessitates \"manual\" memory management, e.g. buffer re-use, arena allocators, etc. The initial \"clean\" C++ version was nearly 3x slower than the final - much, much slower than the Go or Java versions. In order to achieve the desired performance, you end up creating \"restrictive/bug-prone\" apis. For instance, the Google API docs state:\n\n    \u003e Caller should delete the iterator when it is no longer needed.\n    The returned iterator should be deleted before this db is deleted.\n\n    and\n\n    \u003e Return the value for the current entry.  The underlying storage for\n    the returned slice is valid only until the next modification of the iterator.\n\n    Which works, but it does make the api more fragile (i.e. error prone). Often the inefficiency is simply pushed farther (e.g. you can't store the returned iterator value in a map without a copy).\n\n1. Compilation times are extremely slow, especially when using higher optimization levels. Since C++ does not use a context-free grammar everything must be recompiled almost always.\n1. Writing lock-free data structures is much easier in a GC language due to the [ABA problem](https://en.wikipedia.org/wiki/ABA_problem). `std::atomic` helps but using a well-tested library like Boost is probably safer. Still, I was able to implement the concurrent skip list in a lock-free manner.\n1. Cryptic error messages. Missing a single character can lead to a 100 line error across multiple files. Same underlying cause as the slow compile times.\n1. Having to work with both header and implementation files is a pain.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobaho%2Fcpp_leveldb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frobaho%2Fcpp_leveldb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobaho%2Fcpp_leveldb/lists"}