Optimize dbBox serialization and deserialization - #11225
Optimize dbBox serialization and deserialization#11225debayanbandyopadhyay wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors the serialization and deserialization of _dbBox (both rectangular and octagonal shapes) to use raw byte streaming via std::span and std::bit_cast, improving performance and simplifying the code. It also adds a comprehensive unit test to verify the correctness of the serialization. The feedback suggests enhancing safety and robustness by adding compile-time size assertions for the serialization structures and replacing hardcoded magic numbers in the byte-writing operations with sizeof expressions.
eaa5d2f to
641f596
Compare
8c52e51 to
264b7de
Compare
856bd52 to
9bb0892
Compare
Signed-off-by: Debayan Bandyopadhyay <dbandyopadhyay@google.com>
9bb0892 to
47c66f6
Compare
|
@codex review |
|
Codex Review: Didn't find any major issues. Delightful! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
I see the gain is real but the cost is a lot of extraneous structs and code complexity. I explored some alternatives with Claude and I think this is a better approach The main savings you are getting is from reducing the number of calls to writeBytes and this achieves the effect in a simpler fashion. Then you can do |
Summary
This PR optimizes the serialization and deserialization of
_dbBoxin ODB to improve database write/read performance.Key changes:
operator<<): Replaced field-by-field serialization of_dbBoxflags, shapes (Rect/Oct), and metadata with flattened raw byte writes (stream.writeBytes) using robustsizeofformulas to calculate layout sizes safely without magic numbers.operator>>): Refactored deserialization to read raw bytes into structured data blocks (OctData,RectData, etc.) and safely unpack them into_dbBoxfields using a newunpack_boxhelper.std::bit_castand C++20 concepts (std::is_trivially_copyable). Addedstatic_assertsize checks for geometric shapes and serialization structs to guarantee layout consistency across platforms.DbBoxSerializationPublicunit test inTestDbStream.cppthat verifies serialization/deserialization correctness and schema compatibility for bothRectandOctboxes. The test is implemented using only public ODB APIs to comply with Bazel build module/layering boundaries.Type of Change
Impact
This change improves ODB database write performance. Internal Google3 benchmarks on design writes showed a 11% to 17% write-time speedup (average ~15.5% improvement) with no changes to the database schema or user-facing behavior.
Verification
./etc/Build.sh).Related Issues
N/A