-
Notifications
You must be signed in to change notification settings - Fork 47
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
feat: optimize common case of GlobPath #180
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good, thank you. Can we please just tune the suffix function so it looks like the prefix one, but inverted? See details below.
ai := strings.LastIndexAny(a, "*?") | ||
la := 0 | ||
if ai != -1 { | ||
la = len(a) - ai - 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These algorithms are exact opposites of one another, so I'm missing why a choice was made not to implement them as such as well.
For example, if we look at the prefix function, the opposite would be:
if ai == -1 {
ai = 0
}
Right? Doing something entirely different besides being more work, it seems, is also unnecessary cognitive load.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am probably thinking of the wrong algorithm but I do not think the above will work. We use the indexes for the prefix because they coincide with the prefix length, which is what we really want. Conversely, for the suffixes we want to compare the lengths of the suffixes to get the minimum one and, as far as I know, we cannot do that using indexes without calculating the deltas first because there is no correspondence between index and length. For example:
foo*baz
foobar*b
We know that the indexes are 3 and 6 respectively. If we take the minimum of the position then I do not see how to get to the fact that we should check only the last character of both strings because the minimum length of the suffix is 1.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We must be talking about different things. I'm not suggesting a change in algorithm, but rather just pointing out that the algorithm was laid out differently between the suffix and prefix version. The actual comparison is exactly the same at the end.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am talking about this sentence for example:
At first I thought this was wrong, again because I had the prefix logic in mind and didn't realize here it's the minimum of the delta, rather than the minimum of the position
I cannot make it like the prefix logic that uses the position because for suffix position != length of the suffix. Meaning I have to use the deltas, unless I am missing something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think you are missing something.
What's the difference between a[len(a)-minl:]
and a[ai:]
? :)
if bi != -1 { | ||
lb = len(b) - bi - 1 | ||
} | ||
minl := min(la, lb) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The opposite would be max here. At first I thought this was wrong, again because I had the prefix logic in mind and didn't realize here it's the minimum of the delta, rather than the minimum of the position, per logic above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm moving this on. We can discuss semantics tomorrow in our call for alignment, but this is not important enough right now, and I'd rather have it merged before holidays.
Results of the benchmark on my machine (using hyperfine with 10 rounds). Basically, HEAD takes 5.341s on my machine compared to 18.366s for main. $ bash benchmark.sh HEAD main Creating rev: e2ee603 (main) Creating rev: 1982979 (HEAD) Benchmark 1: ./19829794e6454f78334c9a67b74d8abb9bc66b25 info --release ../chisel-releases/ubuntu-24.04 'python3.12_core' Time (mean ± σ): 5.341 s ± 0.115 s [User: 5.528 s, System: 0.028 s] Range (min … max): 5.239 s … 5.635 s 10 runs Benchmark 2: ./e2ee603c7396b33038e47352c0722b5b1202fbfe info --release ../chisel-releases/ubuntu-24.04 'python3.12_core' Time (mean ± σ): 18.366 s ± 0.139 s [User: 19.677 s, System: 0.103 s] Range (min … max): 18.219 s … 18.675 s 10 runs Summary ./19829794e6454f78334c9a67b74d8abb9bc66b25 info --release ../chisel-releases/ubuntu-24.04 'python3.12_core' ran 3.44 ± 0.08 times faster than ./e2ee603c7396b33038e47352c0722b5b1202fbfe info --release ../chisel-releases/ubuntu-24.04 'python3.12_core'
Results of the benchmark on my machine (using hyperfine with 10 rounds). Basically, HEAD takes 5.341s on my machine compared to 18.366s for main. $ bash benchmark.sh HEAD main Creating rev: e2ee603 (main) Creating rev: 1982979 (HEAD) Benchmark 1: ./19829794e6454f78334c9a67b74d8abb9bc66b25 info --release ../chisel-releases/ubuntu-24.04 'python3.12_core' Time (mean ± σ): 5.341 s ± 0.115 s [User: 5.528 s, System: 0.028 s] Range (min … max): 5.239 s … 5.635 s 10 runs Benchmark 2: ./e2ee603c7396b33038e47352c0722b5b1202fbfe info --release ../chisel-releases/ubuntu-24.04 'python3.12_core' Time (mean ± σ): 18.366 s ± 0.139 s [User: 19.677 s, System: 0.103 s] Range (min … max): 18.219 s … 18.675 s 10 runs Summary ./19829794e6454f78334c9a67b74d8abb9bc66b25 info --release ../chisel-releases/ubuntu-24.04 'python3.12_core' ran 3.44 ± 0.08 times faster than ./e2ee603c7396b33038e47352c0722b5b1202fbfe info --release ../chisel-releases/ubuntu-24.04 'python3.12_core'
Results of the benchmark on my machine (using hyperfine with 10 rounds):
Basically, HEAD takes 5.341s on my machine compared to 18.366s for main.