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

Rules now precompute their own regexes and are reusable. #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tobz
Copy link

@tobz tobz commented Nov 6, 2018

Establishing a new MobileDetect object per request is reasonable as there's request data tied to it, but for normal usage, the rules used to do mobile detection never changed at runtime. Despite this, we were previously creating brand new rules objects, and recompiling all of our regular expressions, for each new MobileDetect.

This PR changes it so that you can pre-create the rules and then continually pass them to NewMobileDetect, reusing them over and over. As the data never changes, it's safe for concurrent usage amongst multiple goroutines. This significantly speeds up runtime execution as we're no longer allocating every single time and no longer endlessly recompiling regular expressions.

I also removed the handler/mux stuff because the implementation was weird and it's not hard for people to implement themselves, in a better/faster way.

Signed-off-by: Toby Lawrence [email protected]

Establishing a new MobileDetect object per request is reasonable as
there's request data tied to it, but for normal usage, the rules used to
do mobile detection never changed at runtime.  Despite this, we were
  previously creating brand new `rules` objects, and recompiling all of
  our regular expressions, for each new `MobileDetect`.

This PR changes it so that you can pre-create the rules and then
continually pass them to `NewMobileDetect`, reusing them over and over.
As the data never changes, it's safe for concurrent usage amongst
multiple goroutines.  This significantly speeds up runtime execution as
we're no longer allocating every single time and no longer endlessly
recompiling regular expressions.

Signed-off-by: Toby Lawrence <[email protected]>
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.

1 participant