Skip to content

perf: optimize varint and packed fixed-width paths#39

Merged
anthonyprintup merged 5 commits into
mainfrom
codex/protocyte-optimizations
Jul 7, 2026
Merged

perf: optimize varint and packed fixed-width paths#39
anthonyprintup merged 5 commits into
mainfrom
codex/protocyte-optimizations

Conversation

@anthonyprintup

Copy link
Copy Markdown
Owner

Summary

  • Add a one-byte fast path for runtime varint reads.
  • Add bulk fixed-width packed scalar helpers for contiguous read/write paths.
  • Update generated C++ to use the fixed-width packed helpers where safe.
  • Keep signed fixed-width packed fields on the existing per-element path.
  • Remove lambda/monadic chaining from generated/runtime hot-path code.
  • Add runtime smoke coverage and generator source-shape assertions.

Performance and Size Notes

  • Targeted benchmark runs showed useful wins around fixed-width packed parsing/serialization, but the benchmark environment is noisy, so this PR does not claim a stable end-to-end percentage improvement.
  • protocyte_host_benchmark.exe remains 523,776 bytes after the retained changes.
  • Generated message headers are net smaller by 169 LOC versus the pre-optimization branch state.
  • Layout packing and broader map rewrites are intentionally deferred.

Verification

  • uv run ruff check src\protocyte\cpp.py tests\test_plugin.py
  • uv run pytest tests\test_plugin.py -q
  • git diff --check HEAD~1..HEAD
  • cmake --build tests\smoke\build\clangcl --target protocyte_host_smoke -- -j1
  • tests\smoke\build\clangcl\protocyte_host_smoke.exe
  • cmake --build tests\smoke\build\clangcl-benchmarks --target protocyte_host_benchmark protocyte_host_benchmark_smoke -- -j1
  • tests\smoke\build\clangcl-benchmarks\protocyte_host_benchmark_smoke.exe

Add a direct fast path for one-byte varint reads and replace length-delimited size parsing's hot Result chain with direct checks.

Regenerate the checked smoke runtime output and cover the source shape with a focused runtime test.

Benchmarked with repeated Google Benchmark JSON output; the kept parse-only candidate avoided the write-side regression seen in broader variants.
Add direct host smoke coverage for read_varint canonical byte sequences, including single-byte values, two-byte values, and the 10-byte uint64 maximum.

Cover truncated continuation input and overflowing 10th-byte input so the runtime helper optimization is pinned to observable wire-format behavior.
Add runtime helpers for bulk fixed-width packed scalar read/write paths and wire generated C++ to use them where safe.

Reduce generated hot-path lambda/monadic chaining while preserving explicit status propagation and add smoke/plugin coverage for the optimized source shape.
@anthonyprintup
anthonyprintup force-pushed the codex/protocyte-optimizations branch from 42ddfbb to 4935b4a Compare July 7, 2026 14:46
@anthonyprintup

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4935b4a95b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

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".

Comment thread src/protocyte/cpp.py
Comment thread src/protocyte/runtime/runtime.hpp Outdated
Comment thread src/protocyte/runtime/runtime.hpp Outdated
Restrict generated fixed-width packed direct parsing to little-endian readers whose field storage exposes a Status-returning bulk reader append API, preserving staged rollback behavior for other paths.

Preserve aliased Vector::append_trivial_range sources across reserve growth and keep range assignment constructor fallback available for assignable-but-not-default-constructible element types.

Add smoke regressions and update generated header shape assertions.
@anthonyprintup

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6490426b92

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

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".

Comment thread src/protocyte/cpp.py Outdated
Comment thread src/protocyte/runtime/runtime.hpp
Guard generated packed scalar commit fast paths behind append_trivial_range support so custom Vector implementations can use the reserve/push_back fallback.

Return fixed-width packed preflight errors before appending to the caller output, including misaligned byte counts and readable-size failures.

Document the current custom Config surface directly and add smoke regressions for push-only vectors and malformed fixed-width packed payloads.
@anthonyprintup
anthonyprintup force-pushed the codex/protocyte-optimizations branch from 17e4979 to 8486c1a Compare July 7, 2026 16:31
@anthonyprintup

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: 8486c1a3e4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

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".

@anthonyprintup
anthonyprintup marked this pull request as ready for review July 7, 2026 21:26
@anthonyprintup
anthonyprintup merged commit 0cdb58c into main Jul 7, 2026
8 checks passed
@anthonyprintup
anthonyprintup deleted the codex/protocyte-optimizations branch July 7, 2026 21:34
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