Rules now precompute their own regexes and are reusable. #1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 newrules
objects, and recompiling all of our regular expressions, for each newMobileDetect
.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]