Optimize ISO datetime parsing using binary pattern matching with nibbles#14177
Optimize ISO datetime parsing using binary pattern matching with nibbles#14177dkuku wants to merge 3 commits intoelixir-lang:mainfrom
Conversation
|
Thank you! I would like to hear opinions on this one, because it may be that we find the code more confusing and the gain is small. |
|
I know, this is a good candidate for a macro or to include it in the core: |
|
@dkuku why don't we give such a macro a try then on this change? And then it may clean up the code a bit? |
|
@josevalim It works but I need to define it in a separate module because - probably because this code is not inside a function. |
|
The longer I think about it the more I think such match should be implemented in otp. Matching and parsing integers from binaries is much more common than utf. |
|
Thank you for exploring this. I think between the verbosity and introducing a module only for this, we are stuck between a rock and a hard place, so it is best if we don't go ahead for the gains. Maybe we can have breakthroughs in the future and revisit this. Thank you! |
I promise this is the last one. To be honest, I started with this idea, but I found other parts of this module that benefited more from the changes. However, I've had this in the back of my mind and needed to at least propose it for discussion.
This PR optimizes the parsing of ISO format dates and times by leveraging more efficient binary pattern matching. Key changes include:
The measured performance is almost the same, but there is a noticeable reduction in memory usage (approximately 40 bytes - correlating with the removal of zero guards and subtraction operations).
Note: This optimization was previously considered for nimble_parsec but showed suboptimal performance on BEAM versions prior to OTP 26.