-
-
Notifications
You must be signed in to change notification settings - Fork 55
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
[Startup performance] Stop getting the local_timezone
when it's not required
#650
Comments
Thank you! Not sure how we missed this in profiles so far. I guess it became slower with #511 because now we're loading the tz database from disk. Conceptually, this is similar to the problem we had with currency conversion factors. We want to initialize variables/units with a value that is expensive to look up. Lazy loading would be an obvious solution here, but might be a bit tricky to implement? I haven't thought deeply about it but maybe, instead of calling
where It would be fantastic if we could find a solution that would solve this uniformly, across currencies and timezone objects (and potentially others). Maybe some kind of language feature that allows variables and units to be defined lazily. Like a If all of that turns out to be completely over-engineered, I'd also be fine with turning |
To me, this looks like the easiest for this specific case, but I’m not sure if it’s a breaking change. 🤔 |
I have actually been thinking about how having lazy loaded values could be useful for function local variables. I have often needed to use an if-then-else expression to ensure that a calculation is valid because it is valid only in some branches. A lazy value would simplify this significantly in addition to the benefits for this and similar issues. I don't know if it is the best solution for this particular issue, but as a feature in general I think it would be beneficial in any case. |
Part of #525
The culprit
Hey, I profiled numbat once again while running
1 + 1
and noticed that 23% (~10ms out of 40) of the time was spent running theffi::get_local_timezone
function of numbat.The call comes from this line:
numbat/numbat/modules/datetime/functions.nbt
Lines 28 to 29 in 8470407
And after commenting it and benchmarking the startup time with hyperfine here are the results I got:
So it’s pretty much what I measured with my profiler, 1.28 times or ~10ms faster.
The solution
I’m not sure of what should be the solution here though, maybe make the whole
local
variable a ffi function?Not a fan though, maybe you’ll have a better idea
The text was updated successfully, but these errors were encountered: