Closed nakedible closed 1 year ago
@jhpratt We had a discussion elsewhere how time
library optimization is important. This is probably quite relevant :-)
This is basically why the README says that it's best to float an idea by me first. To be direct, there is zero chance of me relying on another crate for the core functionality of time
, particularly by an author that I am not familiar with. This is primarily due to supply chain security concerns.
With that said, I have no issue replacing the algorithms if they can be made more performant. The benchmarks in this crate are far from perfect in capturing the general use case, so they should be taken with a grain of salt. Of course, large improvements aren't much of a question.
One more note, I am not interested in changing Date
to be represented as year-month-day instead of year-ordinal. The latter is used as it simplifies quite a bit.
Don't worry – I knew I was taking a risk spending the time on this without talking to you first. But I also suspected that I'd have no chance at all to convince you if I didn't show significantly superior performance across the board, because as you don't know me it doesn't carry very far if I just say to you that "trust me, it's better this way". And it's good to get a clear answer as to what you think of it.
At least now you know that these performance gains are possible and you can look at the algorithms in datealgo
: https://github.com/nakedible/datealgo-rs/blob/master/src/lib.rs
To be clear, I'm not personally interested in doing the work to duplicate the algorithms inside datealgo
bit by bit in the time
crate. The license is the same, so feel free to adapt whatever you want though – I'm fully supportive of that. I will however keep benchmarking against the time
crate to see how the optimizations progress :-)
I'll close this pull as I don't intend to take it further, but I'll leave the repo and code around for reference if anyone else stumbles upon it.
Sounds good. Given the performance numbers, I will definite be looking into changing the implementations are some point. It's not a priority of mine, as I'm working on tzdb integration at the moment.
This pull does quite a big root-canal rework:
Date
internal representation is changed from(year: 21 bits, ordinal: 9 bits)
to(year: 21 bits, month: 4 bits, day: 5 bits)
datealgo
libraryThe results of this are performance gains:
As can be seen, the performance gains are quite sizeable. The only regressions are
from_ordinal_date
,ordinal
andto_ordinal_date
, all of which are obvious. Ordinal based operations are not terribly common, so I would expect the improvements in real world usage to be a clear net positive.Disclaimer: I am the creator of the
datealgo
library, although I do not claim credit for the algorithms themselves.NOTE: Pull is still a draft, so code has a bunch of
FIXME
comments and other things. Also, performance results are preliminary as benchmarks are noisy, so more careful benchmarking is still needed. However, I wanted to get this out early, in order to get feedback before completing the rest.