Skip to content

perf: compact runtime and storage member layouts - #317

Draft
thweetkomputer wants to merge 2 commits into
mainfrom
perf/compact-member-layouts
Draft

thweetkomputer wants to merge 2 commits into
mainfrom
perf/compact-member-layouts

Conversation

@thweetkomputer

@thweetkomputer thweetkomputer commented Oct 12, 2026 •

Copy link
Copy Markdown
Collaborator

Context

Several frequently retained runtime and storage types place small fields between aligned members, increasing object, vector, and coroutine-frame footprints. This change groups fields so the resulting branch can be benchmarked against Lavik 8028ec3e3 and its pinned Bycorf 7904686.

Behavior before and after

Member types, defaults, request behavior, ownership, and durable/wire encodings are unchanged. Measured AArch64/GCC 13.3 sizes with tracing disabled:

Type Before Combined PR
Bycorf RemoteWork 40 B 24 B
Bycorf Task<absl::Status>::promise_type 48 B 40 B
Bycorf SizeIoAwaitable 96 B 88 B
Bycorf OpenFixedFileAwaitable 96 B 88 B
Bycorf Connection 240 B 232 B
TxUndoEntry 136 B 120 B
OrderedGroupEntry 120 B 112 B
ScanHashMap::RehashMove 24 B 16 B
Transaction 616 B 568 B
StagingSlot 56 B 48 B
ReplicaTransactionArrival 256 B 240 B
ConnectionContext::WatchedKey 72 B 64 B
RespCommandParser 144 B 136 B
ConnectionContext 320 B 312 B
CapturedBlockingNotification 48 B 40 B

Transaction is 600 B with only the Lavik changes; the combined 568 B includes smaller embedded Bycorf state. Coroutine promises and awaiters also shrink for representative return types/captures; the companion PR reports those instances.

Implementation

  • Group small fields while preserving relative ordering of nontrivial owners and the transaction's adjacent cross-worker state.
  • Update positional/designated aggregate initializers in production code and existing tests.
  • Pin the companion Bycorf change: perf: compact coroutine and I/O state member layouts bycorf#13.
  • Keep the Lavik changes and the Bycorf pin in separate commits for isolated performance comparisons.

Design decisions and alternatives

Use ordinary member ordering, without packed layouts, narrower field types, new synchronization, or altered cache-line isolation. Leave the replication flow/snapshot atomic layouts outside this change. Public C++ layout changes require a consistent rebuild of Bycorf and all consumers.

Documentation and comments

Add local comments explaining padding-sensitive ordering. Architecture documentation is unchanged: no core boundary, flow, lifecycle, ownership invariant, or durable/wire format claim changes. Keep this audit's measurements in PR context.

Test plan

Run in the AArch64 development environment:

cmake --build build_debug --target lavik lavik_unit_tests bycorf_task_transfer_check bycorf_connect_timer_check bycorf_connection_storage_check bycorf_backend_selection_check lavik_multi_exec_e2e_test lavik_grouped_ordered_write_e2e_test lavik_replica_abort_reclaim_e2e_test lavik_cluster_replication_manager_integration_test --parallel 6
build_debug/lavik_unit_tests --gtest_output=xml:/tmp/lavik-layout-audit/unit-tests.xml
ctest --test-dir build_debug --output-on-failure -j 2 -R '^(bycorf_|lavik_multi_exec_e2e$|lavik_grouped_ordered_write_e2e$|lavik_replica_abort_reclaim_e2e$|lavik_replica_abort_small_stack$|cluster_integration\.replication_manager_control_api$)'
  • Build passed; all 856 unit tests passed.
  • All nine selected CTest regressions passed (814.47 seconds), including grouped storage/recovery, replication management, MULTI/EXEC, replica abort/small-stack, and all four Bycorf checks.
  • Actual-header size probes passed; Bycorf additionally checked with Clang 18 and latency tracing enabled/disabled.
  • pre-commit run --files <changed C++ files> and git diff --check passed in both repositories.
  • No performance benchmark or optional DPDK/SPDK build was run.

Risk assessment

Field ordering changes cache placement and coroutine frame size, so throughput/tail-latency effects require measurement. The coroutine pool's size classes can absorb a sizeof reduction without reducing actual allocation. All consumers must rebuild; do not mix objects compiled against different layouts.

Rollback plan

Revert the two commits and rebuild, restoring the previous Bycorf pin and member layouts. No data migration is needed.

Reviewer guide

Review declaration reordering and initializer changes in the first commit, then the companion Bycorf PR and pin in the second. The Lavik-only commit is 599a9c8cb; combined head is a40703eaa (Bycorf 05d14a8). Run git submodule update --init bycorf after each checkout so the benchmark uses the corresponding runtime.

Follow-up work

Benchmark the baseline, Lavik-only commit, and combined PR with identical Release configuration and workloads. Compare throughput, tail latency, and memory; no performance gain is claimed from size probes alone.

Summary by CodeRabbit

  • Chores
    • Updated the bycorf subproject reference.
    • Reorganized internal data layouts without changing behavior or user-facing functionality.

Performance isolation follow-up

This PR is back in draft while investigating the reported single-key GET/SET performance regression against main. No cause has been established and no corrective change is claimed.

Variant Lavik commit Bycorf commit
Main baseline 8028ec3e3 7904686
Lavik member reordering only 599a9c8cb 7904686
Bycorf member reordering only 77af0e2c4 05d14a8
Combined PR a40703eaa 05d14a8

The added Bycorf-only comparison branch changes only the submodule pin relative to the exact main baseline. Its server and storage-read translation units pass GCC syntax checking with -Werror=reorder; this comparison variant has not undergone a full build, runtime test suite, or performance benchmark. Use separate worktrees/build directories, synchronize submodules for each revision, and keep build and benchmark settings identical. Focus the next repeated comparison on the io_uring 1:1 workload before testing individual reversions.

@coderabbitai

coderabbitai Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: cf17999f-92c6-4d18-870a-bdc955425eb8
📥 Commits

Reviewing files that changed from the base of the PR and between 8028ec3 and a40703e.

📒 Files selected for processing (16)
  • bycorf
  • include/lavik/command.h
  • include/lavik/resp.h
  • include/lavik/session.h
  • include/lavik/storage/detail/grouped/collection.h
  • include/lavik/storage/scan_hash_map.h
  • include/lavik/tx/transaction.h
  • src/redis/blocking_wait.cpp
  • src/redis/command.cpp
  • src/replication/replication_internal.h
  • src/storage/engine/checkpoint.cpp
  • src/storage/engine/grouped/ordered_mutation.cpp
  • src/storage/engine/impl.h
  • src/storage/engine/write.cpp
  • tests/grouped/collection_test.cpp
  • tests/grouped/sorted_rewrite_test.cpp

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Walkthrough

The change reorders members in runtime and storage structures and updates related aggregate initializers without changing their values. It also updates the recorded bycorf subproject commit.

Changes

Member Layout and Initializer Alignment

Layer / File(s) Summary
Runtime state layout
include/lavik/command.h, include/lavik/resp.h, include/lavik/session.h, include/lavik/tx/transaction.h, src/replication/replication_internal.h
Members were reordered in command, parser, session, transaction, and replication structures. The field types and defaults remain unchanged.
Storage structure layout
include/lavik/storage/detail/grouped/collection.h, include/lavik/storage/scan_hash_map.h, src/storage/engine/impl.h
Members were reordered in grouped collection, hash-map, staging-slot, and transaction-undo structures.
Runtime aggregate initializers
src/redis/blocking_wait.cpp, src/redis/command.cpp
Blocking notification and WATCH initializers now follow the corresponding member declaration order.
Storage initializers and tests
src/storage/engine/checkpoint.cpp, src/storage/engine/grouped/ordered_mutation.cpp, src/storage/engine/write.cpp, tests/grouped/*
Ordered-group and transaction-undo initializers, and grouped collection test initializers, now follow the updated member order. Values and test behavior remain unchanged.

bycorf Subproject Reference

Layer / File(s) Summary
Subproject reference update
bycorf
The recorded subproject commit changed from 7904686b97ca107b4adaee1982f13742995a3430 to 05d14a820292337d7692ba0b530cedca1f3124c2.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Refactor

Suggested reviewers: liunyl

Merge Risk: ⚪ Minimal · up to a4070

No concrete runtime or durable-format regression was established. Consumers must be rebuilt consistently with the updated layouts; no other actionable merge-blocking risk is identified.

Pre-merge checks · Passed 4 · Inconclusive 1

Failed Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage Inconclusive Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 18 functions across 14 files. (2 skipped:… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks (4 passed)
Check name Status Explanation
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Title check Passed The title clearly and concisely describes the main change: compacting runtime and storage member layouts for performance.
Description check Passed The description includes all required template sections and provides context, behavior changes, implementation details, design decisions, documentation status, test results, risks, rollback, reviewer …
Full details: Docstring Coverage

Explanation

Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 18 functions across 14 files. (2 skipped: 1 unsupported, 1 too large.)

✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

A rabbit checks the fields in rows,
Then hops where each initializer goes.
The scores stay put, the values too,
A fresh commit joins the review queue.
Soft paws mark the change as done.

Comment @coderabbitai help to get the list of available commands.

@thweetkomputer
thweetkomputer marked this pull request as ready for review October 12, 2026 15:24
@thweetkomputer
thweetkomputer marked this pull request as draft October 13, 2026 04:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant