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

Optimize has() #770

Merged
merged 2 commits into from
Aug 13, 2024
Merged

Optimize has() #770

merged 2 commits into from
Aug 13, 2024

Conversation

thomas-brx
Copy link
Contributor

@thomas-brx thomas-brx commented Aug 13, 2024

O(n) -> O(1) for route checks.

In our application, the has method came out on the top in our profiling. It may be that we are calling it too often for some reason, but it prompted this PR to optimize the method.

Note - got the tests running after patching one FolioTest to ignore ordering of the routes array. Don't know if this is ok or not.

@thomas-brx thomas-brx mentioned this pull request Aug 13, 2024
@bakerkretzmar
Copy link
Collaborator

Thanks! Just for reference (I had to look it up), O(n)→O(1) means that currently this operation's performance depends on the size of the routes object, so with thousands of routes it would take longer to make a has() check, whereas after this PR that won't matter, checking for a route will take the same amount of time no matter how many routes there are—right?

@bakerkretzmar bakerkretzmar merged commit a8a5984 into tighten:2.x Aug 13, 2024
22 checks passed
@thomas-brx
Copy link
Contributor Author

Thanks! Just for reference (I had to look it up), O(n)→O(1) means that currently this operation's performance depends on the size of the routes object, so with thousands of routes it would take longer to make a has() check, whereas after this PR that won't matter, checking for a route will take the same amount of time no matter how many routes there are—right?

Thanks @bakerkretzmar, that is a perfect explanation :) Sorry for being so cryptic in my description.
Your work with ziggy is much appreciated 🏅

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.

2 participants