Repository navigation
Conversation
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>
|
Wouldn't it be a better solution to re-use the encoder accross calls? |
The object gets modified during encoding. |
|
You mean |
|
I agree we could refactor In general |
json.dumps() builds a new encoder on every call, so this is per-call overhead for small payloads.
@vectorcallrequires an immutable type: setting attributes on_json.Encodernow raises TypeError. Bad separators are now named ("argument 'key_separator'") instead of "argument 5".pyperformance, PGO+LTO:
pyperf microbenchmarks, PGO+LTO: