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

Skip to content

Compile regexes lazily #57

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

Closed
wants to merge 1 commit into from
Closed

Conversation

jonashaag
Copy link

Safe 90% of import duration by calling 're.compile' only on first access.

Safe 90% of import duration by calling 're.compile' only on first access.
@jonashaag
Copy link
Author

Test failures are unrelated to my changes.

@jonashaag
Copy link
Author

bump

@jonashaag
Copy link
Author

Anything I can do to get this merged?

@mattrobenolt
Copy link
Member

I'm personally a bit indifferent on optimizations like this. Because there are pros and cons to this. In a web application, I'd rather take the performance hit on application boot up, not the first time I parse a user agent string. If I take the hit on application boot, I can assure processing requests and doing real work is going to be a more predictable speed instead of the first request being handled much slower than subsequent ones.

So I'm personally a -1 on this since I'd rather spend the upfront time during process boot. I feel it's unlikely that you'd import without an intention to use. In which case, what does this optimize for? Just don't import eagerly if you're optimizing for boot time.

@jonashaag
Copy link
Author

For example using it in a Django application with auto reloading. Adds 1s to you development cycle.

@mattrobenolt
Copy link
Member

So import it elsewhere lazily. In a production Django application, I'd want this preloaded and not add a 1s delay to my first request.

@mattrobenolt
Copy link
Member

My point is that how it's done right now, you have a choice on controlling this. What you're proposing removes the choice and I'm stuck with the behavior that you deem better which is subjective.

If this was that big of a deal, I'd be more open to supporting an environment variable or some other top level way to configure this behavior so you can say UAP_PYTHON_LAZY=1 or something.

@jonashaag
Copy link
Author

You could also say that how it’s done now you do not have a choice except for changing all the import paths in any library that uses uap, which means N times the work of discussion and patching. At the same time, you can force non-lazy compilation by simply adding an access path to your bootstrap code. Admittedly, in that scenario, unless you know there’s this first request “penalty” in uap, it’s not trivial to see why your first request is much slower than the subsequent ones.

I accept your reasoning and decision though, and maybe will bring the issue up in the libraries that use uap.

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