Optimize int encode with direct PyLong digit read#107
Merged
Conversation
Merging this PR will improve performance by 12.33%
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ⚡ | Simulation | test_dag_cbor_encode_real_data[citm_catalog.json] |
8.1 ms | 7.2 ms | +12.33% |
Tip
Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.
Comparing optimize-pylong-int (87d86d2) with main (d2eaf4d)
Owner
Author
|
citm +12% aligns with my local tests; also there are github +4% and twitter +4.6% |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a CPython 3.12+ fast path in
encode_intthat readsPyLongObject.lv_tag+ob_digit[0..2]directly to encode 0/1/2-digit ints (≤ 2**60), skippingobj.extract::<i128>()which internally calls_PyLong_AsByteArraywith a 16-byte buffer + sign check on every intInts requiring 3+ digits, pre-3.12, and non-CPython fall through to the existing
i128path, which still enforces the +-2**64 DAG-CBOR range