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.
Currently, this is the most expensive part of string validation, especially on longer strings. Unfortunately, this method is called quite frequently (eg: user agent), during intercept request, and needs to be cheap.
The 'proper' fix for this would be to subclass String (and all other immutable types), add a flag to set when fully validated, and use that flag instead. Ideally, we could do this for dicts too, so we wouldn't need to do the traversal which is extremely costly, and gets even worse if people have bound a lot of keys.
If you'd like, I could try to solve this a different way. This shouldn't take up much more memory because these strings are sitting in the config system anyway, but I really don't like sticking caches on everything instead of the proper fix.
I also made a profile for looking up default bindings 😢 .
Before:
After
It's weird that the dict benchmark improved from the string cache, but idk...
This change is