Skip to content

feat: static dispatch for jsonrpc request handlers#3649

Draft
brbrr wants to merge 4 commits into
mainfrom
refactor/generics-json-server-main
Draft

feat: static dispatch for jsonrpc request handlers#3649
brbrr wants to merge 4 commits into
mainfrom
refactor/generics-json-server-main

Conversation

@brbrr
Copy link
Copy Markdown
Contributor

@brbrr brbrr commented May 18, 2026

Bench results:

Time (sec/op)

Benchmark main native sonic native vs main sonic vs main
no_params 1.638 µs 1.467 µs 1.070 µs −10.5% −34.7%
one_scalar_pos 2.431 µs 2.385 µs 1.839 µs ~ −24.3%
one_struct_pos 2.991 µs 2.931 µs 1.963 µs ~ −34.4%
three_pos_mixed 3.774 µs 4.101 µs 2.188 µs +8.7% −42.0%
three_named_required 4.045 µs 4.430 µs 2.509 µs +9.5% −38.0%
named_opt_missing 2.526 µs 2.762 µs 2.149 µs +9.3% −14.9%
named_opt_present 4.016 µs 4.328 µs 2.504 µs +7.8% −37.6%
validator_pass 3.003 µs 3.138 µs 2.139 µs ~ −28.8%
validator_fail 3.570 µs 3.905 µs 2.733 µs +9.4% −23.4%
type_error 2.446 µs 2.955 µs 3.232 µs +20.8% +32.2%
batch_small 15.64 µs 15.71 µs 10.41 µs ~ −33.4%
batch_large 140.9 µs 130.9 µs 82.49 µs −7.1% −41.4%
response_100_structs 7.099 µs 6.905 µs 12.19 µs −2.7% +71.7%
geomean 4.819 µs 4.975 µs 3.678 µs +3.2% −23.7%

Allocs/op

Benchmark main native sonic native vs main sonic vs main
no_params 21 19 16 −9.5% −23.8%
one_scalar_pos 32 35 27 +9.4% −15.6%
one_struct_pos 43 39 28 −9.3% −34.9%
three_pos_mixed 56 54 28 −3.6% −50.0%
three_named_required 55 48 26 −12.7% −52.7%
named_opt_missing 33 33 25 ~ −24.2%
named_opt_present 55 48 26 −12.7% −52.7%
validator_pass 42 40 29 −4.8% −31.0%
validator_fail 54 53 42 −1.9% −22.2%
type_error 35 39 43 +11.4% +22.9%
batch_small 131 121 107 −7.6% −18.3%
batch_large 997 897 788 −10.0% −21.0%
response_100_structs 21 20 17 −4.8% −19.1%
geomean 54.24 51.75 38.65 −4.6% −28.7%

Bytes/op

Benchmark main native sonic native vs main sonic vs main
no_params 1.617 KiB 1.578 KiB 1.272 KiB −2.4% −21.3%
one_scalar_pos 1.892 KiB 2.759 KiB 2.512 KiB +45.8% +32.8%
one_struct_pos 2.501 KiB 2.899 KiB 2.675 KiB +15.9% +7.0%
three_pos_mixed 3.017 KiB 3.447 KiB 2.777 KiB +14.3% −7.9%
three_named_required 3.221 KiB 2.978 KiB 3.226 KiB −7.6% ~
named_opt_missing 2.259 KiB 2.392 KiB 2.929 KiB +5.9% +29.7%
named_opt_present 3.229 KiB 2.985 KiB 3.212 KiB −7.5% ~
validator_pass 2.440 KiB 2.848 KiB 2.580 KiB +16.7% +5.7%
validator_fail 3.180 KiB 3.603 KiB 3.656 KiB +13.3% +15.0%
type_error 2.221 KiB 3.072 KiB 3.927 KiB +38.4% +76.9%
batch_small 11.06 KiB 10.86 KiB 10.62 KiB −1.8% −4.0%
batch_large 87.09 KiB 85.13 KiB 89.83 KiB −2.3% +3.2%
response_100_structs 4.213 KiB 4.181 KiB 5.015 KiB −0.8% +19.0%
geomean 3.828 KiB 4.163 KiB 4.203 KiB +8.8% +9.8%

The typed-dispatch refactor only eliminates reflection in the handler call (replacing reflect.Value.Call with a typed closure), but per-request time is dominated by encoding/json's
reflection-driven decode of params — which we still pay because we still use stdlib JSON. The call-site reflection we removed costs ~30-50ns; the per-field json.Unmarshal reflect walks
we kept cost ~400ns each, so the savings get drowned out. The only paths that visibly benefit are call-overhead-dominated ones (no-args, batches, encode-heavy) where the reflect.Call
savings aren't masked — decode-heavy paths come out at parity with main.

@brbrr brbrr self-assigned this May 18, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 18, 2026

Codecov Report

❌ Patch coverage is 41.60959% with 341 lines in your changes missing coverage. Please review.
✅ Project coverage is 71.96%. Comparing base (13295a2) to head (c10229d).
⚠️ Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
rpc/v10/register.go 2.75% 105 Missing and 1 partial ⚠️
rpc/v8/register.go 11.32% 93 Missing and 1 partial ⚠️
rpc/v9/register.go 13.76% 93 Missing and 1 partial ⚠️
jsonrpc/server.go 59.61% 15 Missing and 6 partials ⚠️
jsonrpc/register.go 89.07% 10 Missing and 10 partials ⚠️
rpc/handlers.go 76.92% 0 Missing and 3 partials ⚠️
rpc/v8/subscriptions.go 60.00% 2 Missing ⚠️
rpc/v9/subscriptions.go 75.00% 1 Missing ⚠️

❌ Your patch check has failed because the patch coverage (41.60%) is below the target coverage (60.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3649      +/-   ##
==========================================
- Coverage   77.12%   71.96%   -5.17%     
==========================================
  Files         395      399       +4     
  Lines       35645    36602     +957     
==========================================
- Hits        27492    26340    -1152     
- Misses       6153     8139    +1986     
- Partials     2000     2123     +123     

☔ View full report in Codecov by Sentry.
📢 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.

@brbrr brbrr temporarily deployed to Development May 19, 2026 20:46 — with GitHub Actions Inactive
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