Repository navigation
perf(base64): optimize base64 decode lookup table and quantum loop - #22903
iam-saiteja wants to merge 1 commit into
Conversation
0c85e2c to
d38a5aa
Compare
|
There's already a base64 decoding performance test: (running a debug version on my dev machine) PR Versiongit masterI remember I did that setup code version back in c6f602c and I then wanted to avoid using a full table, but I now think differently and I approve of this approach. |
There was a problem hiding this comment.
🟡 Changes recommended
The documented benchmark source is absent, making the reported performance results unreproducible.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Optimizes Base64 decoding by reducing per-call setup and loop overhead.
Changes:
- Adds a static 256-byte decode table.
- Unrolls four-character quantum decoding and combines validation checks.
File summaries
| File | Description |
|---|---|
lib/curlx/base64.c |
Optimizes lookup and quantum decoding. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 1
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
Thanks! |
|
This graph should soon show the effect of this new code: |
|
Thank you @bagder for testing the benchmark numbers and trusting this optimization! Really happy to contribute to curl. |
|
Moderna hårdvara är lite för bekväm når elementära tonårskonster som lookup-tabeller på 256 tecken glöms bort.
|
What was happening
Every time
curlx_base64_decode()was called, it allocated 256 bytes on the stack and ranmemsetandmemcpyto rebuild a lookup table from scratch. It also decoded each 4-byte chunk using a loop with multiple branches. This added unnecessary CPU overhead on every decode call.What was done
What was the output
The decoding speed improved across all inputs:
All existing unit tests (unit1302) pass with 0 errors.
How it works
decodetable[256]is stored in read-only memory (.rodata) so it is initialized only once at compile time.(v0 | v1 | v2 | v3) & 0x80validates all 4 bytes with one check instead of 4 separate checks.Reproduction
cl /O2 /DHAVE_CONFIG_H /Iinclude /Ilib /Ibuild/lib tests/perf_base64_bench.c lib/curlx/base64.c /Fe:bench.exe./bench.execmake --build build --config Release