Skip to content

chore: optimize serialization by reducing parsing calls#158

Merged
moshloop merged 2 commits into
mainfrom
serialize-opt
May 27, 2026
Merged

chore: optimize serialization by reducing parsing calls#158
moshloop merged 2 commits into
mainfrom
serialize-opt

Conversation

@yashmehrotra

@yashmehrotra yashmehrotra commented May 27, 2026

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • Refactor
    • Optimized internal serialization logic for native type handling to improve code maintainability.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 27, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@yashmehrotra, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 14 minutes and 19 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8d758785-8386-49a6-93db-429e053ad5e8

📥 Commits

Reviewing files that changed from the base of the PR and between 34adc65 and 8eae2b5.

📒 Files selected for processing (3)
  • .github/scripts/benchstat-summary.py
  • .github/workflows/benchmark.yml
  • serialize_bench_test.go

Walkthrough

The PR refactors how Serialize handles native type decompositions by replacing path-string keyed storage with a struct that preserves the original jp.Expr paths and values, collected during jp.Walk, then directly re-applied to the output without intermediate parsing.

Changes

Native decomposition storage refactoring

Layer / File(s) Summary
Native type decomposition storage and re-application
serialize.go
New nativeType struct pairs a jp.Expr path with a decomposed value. Serialize now collects these during jp.Walk (copying paths to prevent walk mutations), applies the base transformation, and restores native values by calling SetOne on stored expressions instead of parsing path strings from a map.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'chore: optimize serialization by reducing parsing calls' accurately describes the main change: refactoring serialization to eliminate intermediate jp.ParseString calls.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch serialize-opt
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch serialize-opt

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

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

@moshloop

Copy link
Copy Markdown
Member

Can we add some benchmarks ?

@yashmehrotra yashmehrotra requested a review from moshloop May 27, 2026 07:46
@github-actions

github-actions Bot commented May 27, 2026

Copy link
Copy Markdown

Benchstat

Base: 43496a8c599270933c753d91a13172aed873ebdc
Head: 8eae2b50e3b3779db6d797c2a639c6b52f587e64

7 minor regression(s) (all within 5% threshold)

Benchmark Base Head Change p-value
Serialize/Size-10-4 10.95Ki 11.06Ki +1.00% 0.002
Serialize_NoNativeTypes/Size-100-4 36.20Ki 36.33Ki +0.35% 0.002
Serialize/Size-100-4 95.41Ki 95.52Ki +0.11% 0.002
Serialize_NoNativeTypes/Size-100-4 910.0 911.0 +0.11% 0.002
Serialize_NoNativeTypes/Size-1000-4 365.4Ki 365.6Ki +0.03% 0.002
Serialize/Size-1000-4 952.4Ki 952.5Ki +0.01% 0.002
Serialize_NoNativeTypes/Size-1000-4 9.757k 9.758k +0.01% 0.011
4 improvement(s)
Benchmark Base Head Change p-value
Serialize/Size-10-4 274.0 268.0 -2.19% 0.002
Serialize_NoNativeTypes/Size-100-4 87.47µ 86.54µ -1.07% 0.002
Serialize/Size-100-4 2.524k 2.518k -0.24% 0.002
Serialize/Size-1000-4 25.81k 25.80k -0.02% 0.002
Full benchstat output
goos: linux
goarch: amd64
pkg: github.com/flanksource/gomplate/v3
cpu: AMD EPYC 7763 64-Core Processor                
                                     │ bench-base.txt │          bench-head.txt           │
                                     │     sec/op     │   sec/op     vs base              │
Serialize/Size-10-4                      36.07µ ± 13%   35.70µ ± 8%       ~ (p=0.485 n=6)
Serialize/Size-100-4                     342.0µ ±  1%   340.5µ ± 1%       ~ (p=0.065 n=6)
Serialize/Size-1000-4                    3.445m ±  0%   3.454m ± 1%       ~ (p=0.818 n=6)
Serialize/Size-10000-4                   36.93m ±  1%   36.55m ± 5%       ~ (p=0.240 n=6)
Serialize_NoNativeTypes/Size-100-4       87.47µ ±  1%   86.54µ ± 0%  -1.07% (p=0.002 n=6)
Serialize_NoNativeTypes/Size-1000-4      883.4µ ±  6%   889.0µ ± 2%       ~ (p=0.699 n=6)
Serialize_NoNativeTypes/Size-10000-4     9.111m ±  0%   9.104m ± 0%       ~ (p=0.699 n=6)
geomean                                  1.014m         1.010m       -0.39%

                                     │ bench-base.txt │           bench-head.txt           │
                                     │      B/op      │     B/op      vs base              │
Serialize/Size-10-4                      10.95Ki ± 0%   11.06Ki ± 0%  +1.00% (p=0.002 n=6)
Serialize/Size-100-4                     95.41Ki ± 0%   95.52Ki ± 0%  +0.11% (p=0.002 n=6)
Serialize/Size-1000-4                    952.4Ki ± 0%   952.5Ki ± 0%  +0.01% (p=0.002 n=6)
Serialize/Size-10000-4                   10.01Mi ± 0%   10.01Mi ± 0%       ~ (p=0.370 n=6)
Serialize_NoNativeTypes/Size-100-4       36.20Ki ± 0%   36.33Ki ± 0%  +0.35% (p=0.002 n=6)
Serialize_NoNativeTypes/Size-1000-4      365.4Ki ± 0%   365.6Ki ± 0%  +0.03% (p=0.002 n=6)
Serialize_NoNativeTypes/Size-10000-4     3.584Mi ± 0%   3.584Mi ± 0%  +0.00% (p=0.002 n=6)
geomean                                  337.2Ki        337.9Ki       +0.21%

                                     │ bench-base.txt │          bench-head.txt           │
                                     │   allocs/op    │  allocs/op   vs base              │
Serialize/Size-10-4                        274.0 ± 0%    268.0 ± 0%  -2.19% (p=0.002 n=6)
Serialize/Size-100-4                      2.524k ± 0%   2.518k ± 0%  -0.24% (p=0.002 n=6)
Serialize/Size-1000-4                     25.81k ± 0%   25.80k ± 0%  -0.02% (p=0.002 n=6)
Serialize/Size-10000-4                    264.8k ± 0%   264.8k ± 0%       ~ (p=0.084 n=6)
Serialize_NoNativeTypes/Size-100-4         910.0 ± 0%    911.0 ± 0%  +0.11% (p=0.002 n=6)
Serialize_NoNativeTypes/Size-1000-4       9.757k ± 0%   9.758k ± 0%  +0.01% (p=0.011 n=6)
Serialize_NoNativeTypes/Size-10000-4      100.1k ± 0%   100.1k ± 0%  +0.00% (p=0.015 n=6)
geomean                                   8.834k        8.804k       -0.34%

@moshloop moshloop merged commit c098213 into main May 27, 2026
8 checks passed
@moshloop moshloop deleted the serialize-opt branch May 27, 2026 07:58
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.

2 participants