-
-
Notifications
You must be signed in to change notification settings - Fork 409
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
Compare any
arrays
#582
Compare any
arrays
#582
Conversation
Nice catch with bools! But yes, I think we should not add cases for arrays. More research is needed here. Maybe a builtin |
Okay, I opened separate PR for bools here.
We can add func Equal(a, b any) {
switch x := a.(type) {
...
}
if res, ok := equalArrays(a, b); ok {
return res
}
return reflect.DeepEqual(a, b) but decrease performance of non-primitive comparisons. Do you have any thoughts how frequently it happens?
Could you please give me couple examples? I think I didn't get it. |
Sounds like a good solution. Make sure it is a deep equal as well:
I don't know ¯\_(ツ)_/¯ I also have an idea to test: add OpEqualInt & OpEqualBool & OpEqualString opcodes. I belive those will be the most common once. BUT, I'm not sure what adding more opcodes will be faster than OpEqual switch, so those changes should be benchmarked. |
The only case I found in my codebase involves
Expr already includes
So if you find a ~2% improvement worthwhile, I can add |
I think we can postpone implementing it. We can focus on features with >10% performance boost. |
So what is the status of this PR? Will we separate array equal cases to a func |
Firstly, I'm gonna write benchmarks for |
I compared master vs extended switch-case:
And extended switch-case vs separate function for arrays:
The difference is just a tiny fraction of a nanosecond. I think we can say they're pretty much the same. What do you think? |
I percentage on ns is definitely not major. Probably is an artifact of benchmarking. Let's just choose the more readable solution. |
Well, IMO this version is better |
We can try to fix #371 with nested comparison of arrays' values but I'm not sure if it's worth it to increase amount of switch-cases for such rare (imo) case.
Also, I found that expr always goes to
reflect.DeepEqual
for bools and fixed it.