Repository navigation
The unreserved set is decided when this compiles, not when it first runs - #4
Merged
Merged
Conversation
encode_table() filled a 256-byte array on its first call, behind a `ready` flag. Two mrb_states reaching that on different threads is a data race - benign in effect, since both write the same values, but a race nonetheless - and it costs a branch on every call for something that cannot change. It is a constexpr std::array now, built by an immediately-invoked lambda. The loops run in the compiler; what reaches the binary is 256 bytes of .rodata. No flag, no branch, nothing to race for. The static_asserts are not decoration - they are only checkable if the table really is finished before main(), which is the entire claim. They also pin the set itself: 'a', 'Z', '0' and '~' in; space, '/' and 0xff out; '+' out, so it encodes to %2B and never to a space (URI.encode is RFC 3986, not form-urlencoded, and test/uri.rb asserts exactly that); and 66 entries total, which is 26 + 26 + 10 + 4. Stating the rule also beats stating the result. A written-out table is 256 hand-counted numbers in which somebody has to notice that 45, 46, 95 and 126 are '-', '.', '_' and '~' before the table says anything - the shape this file had before, when it was C and could not do better. Tests pass under -fsanitize=address,undefined: 2498 total, 0 failures. Co-Authored-By: Claude <noreply@anthropic.com>
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.
encode_table() filled a 256-byte array on its first call, behind a
readyflag. Two mrb_states reaching that on different threads is a data race - benign in effect, since both write the same values, but a race nonetheless - and it costs a branch on every call for something that cannot change.It is a constexpr std::array now, built by an immediately-invoked lambda. The loops run in the compiler; what reaches the binary is 256 bytes of .rodata. No flag, no branch, nothing to race for.
The static_asserts are not decoration - they are only checkable if the table really is finished before main(), which is the entire claim. They also pin the set itself: 'a', 'Z', '0' and '~' in; space, '/' and 0xff out; '+' out, so it encodes to %2B and never to a space (URI.encode is RFC 3986, not form-urlencoded, and test/uri.rb asserts exactly that); and 66 entries total, which is 26 + 26 + 10 + 4.
Stating the rule also beats stating the result. A written-out table is 256 hand-counted numbers in which somebody has to notice that 45, 46, 95 and 126 are '-', '.', '_' and '~' before the table says anything - the shape this file had before, when it was C and could not do better.
Tests pass under -fsanitize=address,undefined: 2498 total, 0 failures.