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

Change ApplicationController's routes's class to Set to speed up "valid_action?" #2182

Merged
merged 1 commit into from
Apr 21, 2022

Conversation

Shell-Wataru
Copy link

I changed ApplicationController's routes's class to Set to speed up valid_action?.

Let N be number of routes.
valid_action? checks all routes in current version. So the time complexity is O(N) .
When we store routes as Set, the time complexity is O(log N) .

My application has hundreds of routes. valid_action? took a long time.

@pablobm
Copy link
Collaborator

pablobm commented Apr 21, 2022

Good call. Thank you!

Incidentally: is it right that the complexity of searching within a Set is O(log(n))? I would have expected it to be O(1), using a hash table or something like that.

@pablobm pablobm merged commit 2101053 into thoughtbot:main Apr 21, 2022
@Shell-Wataru
Copy link
Author

Oh、 You are right. I misunderstood Set's data structure. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants