Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memoize regexps for common character classes #524

Merged
merged 1 commit into from
Nov 15, 2023

Conversation

ianks
Copy link
Contributor

@ianks ianks commented Nov 15, 2023

This PR improves the performance of Addressable::URI#encode and Addressable::URI#encode_component by memoizing the default character class regexes instead of recompiling them on every call. This results in the following performance improvements:

Addressable::URI#encode_component

Addressable::URI#encode_component (old)
                         95.417k (± 1.4%) i/s -    484.347k in   5.077072s

Addressable::URI#encode_component (new)
                        426.794k (± 1.6%) i/s -      2.134M in   5.001961s

Addressable::URI#encode benchmark

Addressable::URI#encode (old)
                         20.800k (± 1.2%) i/s -    105.213k in   5.058973s

Addressable::URI#encode (new)
                         34.344k (± 2.3%) i/s -    174.794k in   5.092458s

Copy link
Collaborator

@dentarg dentarg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

@dentarg dentarg merged commit 20879a9 into sporkmonger:main Nov 15, 2023
33 checks passed
@ianks
Copy link
Contributor Author

ianks commented Dec 8, 2023

@dentarg is there any plan to release main soon-ish? deciding whether we should use github dep in our gemfile or just wait it out

@dentarg
Copy link
Collaborator

dentarg commented Dec 8, 2023

@ianks No plan, I forgot about this change actually. I can do a release. If someone would open a PR like #505 it would help!

@dentarg
Copy link
Collaborator

dentarg commented Dec 8, 2023

(note that there's a rake task to update the gemspec (I have my instructions for doing a release at https://starkast.wiki/addressable))

@dentarg
Copy link
Collaborator

dentarg commented Dec 9, 2023

@ianks 2.8.6 has been released now

@@ -68,6 +69,18 @@ module NormalizeCharacterClasses
QUERY = %r{[^a-zA-Z0-9\-\.\_\~\!\$\'\(\)\*\+\,\=\:\@\/\?%]|%(?!2B|2b)}
end

module CharacterClassesRegexps
AUTHORITY = /[^#{CharacterClasses::AUTHORITY}]/

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
AUTHORITY = /[^#{CharacterClasses::AUTHORITY}]/
AUTHORITY = /[^#{CharacterClasses::AUTHORITY}]/

Repository owner locked as spam and limited conversation to collaborators Sep 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants