Conversation
Instead of calling :binary.split/2 twice per key-value pair (once on "&" and once on "="), decode query parameters directly using binary pattern matching and binary_part/3. This eliminates 2 intermediate list allocations per query pair in URI.query_decoder/2 and URI.decode_query/1,2,3. Assisted-by: Antigravity:Gemini 3.8 Flash
Member
|
Thanks but I will stick to the current patch. It is simpler and it can leverage simd. I also have patches to OTP that optimize split so it may get faster in future versions! |
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.
Summary
Instead of calling
:binary.split/2twice per key-value pair (once on&and once on=), decode query parameters directly using binary pattern matching (parse_next_key/4andparse_next_val/5) andbinary_part/3.This eliminates 2 intermediate 2-element list allocations per query pair in
URI.query_decoder/2andURI.decode_query/1,2,3.Passing sliced sub-binaries directly into
decode_with_encoding/2also opens the door to a future fast path inURI.decode/1andURI.decode_www_form/1(e.g. returning the sub-binary directly without copying or decoding when no percent escapes or plus signs are present).Benchmarks (Benchee, OTP 29)
URI.decode_query
URI.query_decoder |> Enum.to_list
Assisted-by: Antigravity:Gemini 3.8 Flash