8000 Speedup path lookup by avoiding object allocation by luislavena · Pull Request #9 · tbrand/router.cr · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Speedup path lookup by avoiding object allocation #9

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

Merged
merged 1 commit into from
Apr 13, 2017
Merged

Speedup path lookup by avoiding object allocation #9

merged 1 commit into from
Apr 13, 2017

Conversation

luislavena
Copy link
Contributor

Request#resource relies on URI#full_path to combine both path and query elements of the parsed URI in order to construct another string.

By doing that, a few temporary strings are allocated, adding elements for the GC to collect.

That combined with the Regex introduces a slowdown in the lookup, not to mention the call to PCRE (C land).

URI already provides path clean from query parameters and that is exposed as part of the request as path.

You can see the performance differences on the following benchmark:

https://gist.github.com/luislavena/2bbb6befb8c0dd5ea3c7a628aba3d39d

Results:

             URI#path: 423.36M (  2.36ns) (± 1.61%)        fastest
URI#full_path + Regex:   3.44M ( 290.8ns) (± 0.51%) 123.11× slower

Thank you. ❤️ ❤️ ❤️

`Request#resource` relies on `URI#full_path` to combine both `path`
and `query` elements of the parsed URI in order to construct another
string.

By doing that, a few temporary strings are allocated, adding elements
for the GC to collect.

That combined with the Regex introduces a slowdown in the lookup, not
to mention the call to PCRE (C land).

`URI` already provides `path` clean from query parameters and that is
exposed as part of the request as `path`.

You can see the performance differences on the following benchmark:

https://gist.github.com/luislavena/2bbb6befb8c0dd5ea3c7a628aba3d39d

Results:

                 URI#path: 423.36M (  2.36ns) (± 1.61%)        fastest
    URI#full_path + Regex:   3.44M ( 290.8ns) (± 0.51%) 123.11× slower
@tbrand tbrand self-assigned this Apr 13, 2017
@tbrand
Copy link
Owner
tbrand commented Apr 13, 2017

This is an awesome commit! 🎉

@tbrand tbrand merged commit d403912 into tbrand:master Apr 13, 2017
@luislavena luislavena deleted the speedup-path-lookup branch October 9, 2017 13:09
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
0