Skip to content

wip: add CBOR fast path decode#3792

Draft
ongyimeng wants to merge 1 commit into
mainfrom
perf/felt-decode
Draft

wip: add CBOR fast path decode#3792
ongyimeng wants to merge 1 commit into
mainfrom
perf/felt-decode

Conversation

@ongyimeng

Copy link
Copy Markdown
Contributor

Summary

Felt.UnmarshalCBOR previously used fxamacker/cbor’s reflection-based decoder. Since MarshalCBOR always emits a 4-element array of uint64 limbs, decode that shape directly and fall back to the generic decoder for other valid encodings.

Benchmark

Baseline using generic CBOR decode vs fast path, -count=8, benchstat:

sec/op improvement:

Benchmark Baseline Fast path Δ
StateUpdateByBlockNum p50 71.1µs 38.0µs −46.5%
StateUpdateByBlockNum p95 558µs 265µs −52.5%
StateUpdateByBlockNum p99 555µs 264µs −52.5%
BlockByNumber p50 620µs 376µs −39.4%
BlockByNumber p95 3.53ms 1.70ms −51.9%
BlockByNumber p99 5.07ms 2.39ms −52.8%

All results are highly significant: p=0.000, n=8.

B/op and allocs/op are unchanged at approximately 0%, as expected. The fast path avoids reflection CPU overhead in cbor.Unmarshal, while decoded felts allocate the same way.

@codecov

codecov Bot commented Jul 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 82.14286% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.25%. Comparing base (c68a109) to head (68dfa67).

Files with missing lines Patch % Lines
core/felt/felt.go 82.14% 6 Missing and 4 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3792      +/-   ##
==========================================
+ Coverage   75.16%   75.25%   +0.08%     
==========================================
  Files         438      438              
  Lines       39577    39633      +56     
==========================================
+ Hits        29748    29824      +76     
+ Misses       7735     7720      -15     
+ Partials     2094     2089       -5     

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

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