expr: Optimizing for integer values#5614
Conversation
|
nice, did you do some benchmark ? - just curious on what kind of impact this can have |
|
Not yet, was looking if there are some open test data sets available for |
tertsdiepraam
left a comment
There was a problem hiding this comment.
Great! I'm also curious to see the performance impact. I have a few small suggestions, and one case where I think you've accidentally changed the behaviour.
|
Sorry for getting back on this so late, had a busy week! |
There was a problem hiding this comment.
Nice work! I think you took my advice with From a bit too far, but hopefully what I meant is clear now 😄 It is looking better though!
Also those numbers for the performance are super interesting. I wonder why the string operations are slower! Did you try with --release?
|
Thanks for taking a look at it again @tertsdiepraam ! Maybe I should try and do this on a little less noisy system :) |
|
GNU testsuite comparison: |
tertsdiepraam
left a comment
There was a problem hiding this comment.
Excellent! Just one final suggestion. Great benchmarks! I think it makes sense that it's noisy because it's not the biggest improvement, but it is a great change nonetheless!
src/uu/expr/src/syntax_tree.rs
Outdated
| let pos: usize = Option::<usize>::from(pos.eval()?).unwrap_or(0); | ||
| let length: usize = Option::<usize>::from(length.eval()?).unwrap_or(0); |
There was a problem hiding this comment.
I still think this one is weird. Maybe it could be eval_as_usize? Or we could just inline it:
| let pos: usize = Option::<usize>::from(pos.eval()?).unwrap_or(0); | |
| let length: usize = Option::<usize>::from(length.eval()?).unwrap_or(0); | |
| let pos = pos.eval()?.eval_as_bigint().map_or(0, |n| n.to_usize()); | |
| let length = pos.eval()?.eval_as_bigint().map_or(0, |n| n.to_usize()); |
tertsdiepraam
left a comment
There was a problem hiding this comment.
I made a small change (see the last commit), but this looks ready to be merged once the CI is green. Thanks!
|
This is great! Thanks so much for all your help. |
|
green, merged :) |

An attempt at resolving issue #5591