Skip to content

Optimize parsing by compiling regular expressions once#3

Merged
malcommac merged 3 commits intomalcommac:developfrom
omochi:compile-once
Nov 15, 2020
Merged

Optimize parsing by compiling regular expressions once#3
malcommac merged 3 commits intomalcommac:developfrom
omochi:compile-once

Conversation

@omochi
Copy link
Contributor

@omochi omochi commented Oct 26, 2020

I have troubled with this library when I parse 100 user-agent strings at once.

Rule has regex source string and compiles it for every matching.
Compiling large regex such like used in this library is very heavy operation.

It changes Rule to have compiled regex rather than source string.
So if we test many strings, it can reuse compiled regex and improve performance.

In my case, in situation which takes over 6000msec originally,
it reduced to under 150msec.

@malcommac malcommac self-assigned this Nov 15, 2020
@malcommac malcommac added this to the 1.2.0 milestone Nov 15, 2020
@malcommac malcommac changed the base branch from master to develop November 15, 2020 17:51
@malcommac malcommac changed the title Compiles regexp only once Optimize parsing by compiling regular expressions once Nov 15, 2020
@malcommac malcommac merged commit 3398b00 into malcommac:develop Nov 15, 2020
@omochi omochi deleted the compile-once branch November 17, 2020 02:59
@omochi
Copy link
Contributor Author

omochi commented Nov 17, 2020

Thanks for the merge :)

@malcommac
Copy link
Owner

Thank you for your optimization

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants