Conversation
Add fast-paths for 100% valid and printable strings to return [string] immediately, avoiding the chunk loop and allocations entirely for uniform inputs. In the fallback chunk loop: - Reuse the first decoded codepoint and classification, eliminating redundant decoding and the intermediate wrapper. - Replace repeated <> binary concatenation with zero-copy sub-binary slicing via binary_part/3, removing intermediate binary reallocations. Benchee / OTP 29 (1s warmup, 3s time, 1s memory, pre_check: :all_same): | Input | Time parent -> patch (speedup) | Memory parent -> patch (change) | | --- | ---: | ---: | | 11B valid | 748.97 ns -> 59.41 ns (12.61x) | 2.30 KB -> 0.05 KB (-97.6%) | | 11B printable | 856.65 ns -> 74.50 ns (11.50x) | 2.30 KB -> 0.05 KB (-97.6%) | | 1200B valid | 52.00 μs -> 1.44 μs (36.12x) | 239.61 KB -> 0.05 KB (-99.98%) | | 1200B printable | 71.95 μs -> 4.37 μs (16.47x) | 239.61 KB -> 0.05 KB (-99.98%) | | 1200B mixed valid/invalid | 69.06 μs -> 40.80 μs (1.69x) | 215.33 KB -> 181.38 KB (-15.8%) | | 1200B mixed printable | 85.80 μs -> 45.02 μs (1.91x) | 245.34 KB -> 202.66 KB (-17.4%) | Assisted-by: Gemini:3.8-Flash
Contributor
Author
|
Needs more work, closing it for now. |
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.
Assisted-by: Antigravity CLI:Gemini 3.8 Flash
Add fast-paths for 100% valid and printable strings to return [string]
immediately, avoiding the chunk loop in those cases.
In the fallback chunk loop:
redundant decoding and the intermediate wrapper.
slicing via binary_part/3, removing intermediate binary reallocations.
Bench:
Results: