Conversation
Safe 90% of import duration by calling 're.compile' only on first access.
|
Test failures are unrelated to my changes. |
|
bump |
|
Anything I can do to get this merged? |
|
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. |
|
For example using it in a Django application with auto reloading. Adds 1s to you development cycle. |
|
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. |
|
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 |
|
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. |
Safe 90% of import duration by calling 're.compile' only on first access.