Skip to content

perf: read the fields by the offsets of fmap without reflect - #69

Merged
Insei merged 2 commits into
mainfrom
perf/field-access
Oct 19, 2026
Merged

Insei merged 2 commits into
mainfrom
perf/field-access

Conversation

@Insei

@Insei Insei commented Oct 19, 2026

Copy link
Copy Markdown
Owner

The getters called fmap.GetPtr (reflect.NewAt on every read). Now the address is computed by the offsets of fmap, following the pointers of the nested structs stored by pointer; a nil one is an absent value, as before.

Bench module, median of 8 runs, -cpu 1: valid object 463 → 407 ns, invalid 2202 → 2179 ns, allocations unchanged (0 / 14). The docs have the new numbers, the gap to hand-written code is 1.4x.

The getters of the fields called fmap.GetPtr, it builds the pointer by
reflect.NewAt on every read. The address is computed by the offsets of
fmap once per rule set: the offset from the root struct or from the
nearest ancestor stored by pointer, the pointers of these ancestors are
followed, a nil one is an absent value. A valid object: 463 ns to 407 ns
in the bench module, 0 allocations.
@github-actions

github-actions Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark diff: 0216059 → e8b8179 (10 runs)

goos: linux
goarch: amd64
pkg: github.com/insei/valigo
cpu: Intel(R) Xeon(R) Platinum 8370C CPU @ 2.80GHz
           │  base.txt   │              head.txt               │
           │   sec/op    │   sec/op     vs base                │
Validate-4   207.2n ± 0%   141.3n ± 1%  -31.82% (p=0.000 n=10)

           │  base.txt  │            head.txt            │
           │    B/op    │    B/op     vs base            │
Validate-4   0.000 ± 0%   0.000 ± 0%  ~ (p=1.000 n=10) ¹
¹ all samples are equal

           │  base.txt  │            head.txt            │
           │ allocs/op  │ allocs/op   vs base            │
Validate-4   0.000 ± 0%   0.000 ± 0%  ~ (p=1.000 n=10) ¹
¹ all samples are equal

@codecov-commenter

codecov-commenter commented Oct 19, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (0216059) to head (f6b3987).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main       #69   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           35        35           
  Lines         1093      1110   +17     
=========================================
+ Hits          1093      1110   +17     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Insei
Insei merged commit a7612d7 into main Oct 19, 2026
6 checks passed
@Insei
Insei deleted the perf/field-access branch October 19, 2026 08:10
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