Commit 67730ec
committed
perf: use pickle.loads / pickle.dumps when self.(un)pickler is the default.
The serialize / deserialize paths construct a BytesIO and a Pickler
or Unpickler instance per call to support a user-overridable pickler
class. When self.(un)pickler is pickle.(Un)Pickler -- the default --
this is equivalent to pickle.dumps / pickle.loads, which are
implemented in C (_pickle) and skip the Python-level allocation.
Microbench (round-trip a small dict): BytesIO+Unpickler.load 3.08us
vs pickle.loads 1.59us, ~1.94x.1 parent 388ffae commit 67730ec
1 file changed
Lines changed: 11 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| |||
375 | 375 | | |
376 | 376 | | |
377 | 377 | | |
378 | | - | |
379 | | - | |
380 | | - | |
381 | | - | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
382 | 385 | | |
383 | 386 | | |
384 | 387 | | |
| |||
418 | 421 | | |
419 | 422 | | |
420 | 423 | | |
421 | | - | |
422 | | - | |
423 | | - | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
424 | 427 | | |
425 | 428 | | |
426 | 429 | | |
| |||
0 commit comments