gh-162350: Use AC vectorcall for _json.make_encoder to speed up json.dumps (#162376)
gh-162350: Use AC vectorcall for _json.make_encoder
json.dumps() builds a new encoder on every call, so this is per-call
overhead for small payloads.
@vectorcall requires an immutable type: setting attributes on
_json.make_encoder now raises TypeError. Bad separators are now named
("argument 'key_separator'") instead of "argument 5".
pyperformance, PGO+LTO:
| Benchmark | main | branch |
|------------|:-------:|:---------------------:|
| json_dumps | 4.24 ms | 4.00 ms: 1.06x faster |
pyperf microbenchmarks, PGO+LTO:
| Benchmark | main | branch |
|------------------------------------------|:-------:|:---------------------:|
| json.dumps(1) | 456 ns | 409 ns: 1.12x faster |
| json.dumps(small, separators=(',', ':')) | 1.22 us | 1.13 us: 1.07x faster |
| json.dumps(small) | 850 ns | 794 ns: 1.07x faster |
| json.dumps(small, sort_keys=True) | 1.31 us | 1.23 us: 1.07x faster |
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
6 files changed