Optimize hex decoding performance with LUT-based remainder processing#7
Merged
cfcosta merged 1 commit intocfcosta:mainfrom Nov 10, 2025
Merged
Optimize hex decoding performance with LUT-based remainder processing#7cfcosta merged 1 commit intocfcosta:mainfrom
cfcosta merged 1 commit intocfcosta:mainfrom
Conversation
…and support for varied input sizes, add utility functions for benchmarking decode strategies. remove inline from function with hot loop introduce lut handling of remaining (more performant according to benchmark)
Contributor
Author
Owner
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.

Optimize hex decoding performance with LUT-based remainder processing
Overview
This PR significantly improves hex decoding performance by replacing SIMD-based remainder processing with a lookup table (LUT) approach and optimizing the validation path in the main SIMD loops. The optimizations reduce code complexity and improve instruction cache utilization
Key Changes
1. Extracted
decode_intoas separate functiondecode_into, wrapper handles allocation onlyAssembly comparison:
2. LUT-Based Remainder Processing
vpextrbinstructions with bounds checks (~500+ lines assembly)3. Optimized Stack Usage
Assembly Impact Analysis
Before: ~2000 lines with all SIMD code inlined
After: ~100 lines calling separated function
Core Loop (decode_into)
Now in separate compilation unit with better optimization:
Remainder Processing
Before (SIMD with vpextrb):
After (LUT):
Benchmark Suite Enhancements
Added comprehensive benchmarking infrastructure:
1. Multi-Size Testing
Tests 12 different input sizes from 1B to 1MB:
2. Strategy Comparison Benchmarks
New
test-utilfeature enables direct comparison:3. Detailed Profiling
bench_remainder_strategies: Tests pure remainder (2B-30B)bench_remainder_detailed: Per-pair granularity (1-15 pairs)