Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix memoisation of lazy parser & bump version #255

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
Feb 1, 2025

Conversation

masklinn
Copy link
Contributor

@masklinn masklinn commented Feb 1, 2025

Reported by @Rafiot: the lazy parser is not memoised, this has limited effect on the basic / pure Python parser as its initialisation is trivial, but it significantly impact the re2 and regex parsers as they need to process regexes into a filter tree.

The memoization was mistakenly removed in #230: while refactoring initialisation I removed the setting of the parser global.

  • add a test to ensure the parser is correctly memoized, not re-instantiated every time
  • reinstate setting the global
  • add a mutex on __getattr__, it should only be used on first access and avoids two threads creating an expensive parser at the same time (which is a waste of CPU)

Fixes #253

Reported by @Rafiot: the lazy parser is not memoised, this has limited
effect on the basic / pure Python parser as its initialisation is
trivial, but it *significantly* impact the re2 and regex parsers as
they need to process regexes into a filter tree.

The memoization was mistakenly removed in ua-parser#230: while refactoring
initialisation I removed the setting of the `parser` global.

- add a test to ensure the parser is correctly memoized, not
  re-instantiated every time
- reinstate setting the global
- add a mutex on `__getattr__`, it should only be used on first access
  and avoids two threads creating an expensive parser at the same
  time (which is a waste of CPU)

Fixes ua-parser#253
@masklinn masklinn enabled auto-merge (rebase) February 1, 2025 13:48
@masklinn masklinn merged commit ce12905 into ua-parser:master Feb 1, 2025
26 checks passed
@masklinn masklinn deleted the fix-global-parser-memoization branch February 1, 2025 13:56
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.

Default / lazy parser not cached
1 participant