-
Notifications
You must be signed in to change notification settings - Fork 303
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
Faster binary operations #388
base: v3
Are you sure you want to change the base?
Conversation
@geseq While value based semantics can indeed improve performance, this drastically changes the API of Tengo. It would need to be versioned as v3 to make this change. |
I agree |
@geseq In that case, it might be an idea to try to implement full value semantics for all types for v3, not just for integrets. This might seem strange for maps , arrays, etc but it is possible if somewhat unusual. |
I would want to construct benchmarks before I do that, and at the moment my use case doesn't really require it. |
I'm happy for you to look into it and create a PR if you're interested. |
Well, my main interest here is consistency. Now Tengo uses pointer semantics for v2 everywhere and that is easy to remember. Having a mix of pointer and value semantics is more confusing and less straightforward to use |
Most languages have different semantics between primitive and Object types so that shouldn't be a concern. I wouldn't mind implementing value semantics for |
Again, I do agree with you that in the view of backwards compatibility this shouldn't go into v2, but the performance gains are fairly clear so I would think it's a worthwhile addition. |
curious. why couldn't you make bool value sematics? |
Sorry, I just didn't think of it at first. As I mentioned a couple of posts above, i wouldn't mind doing Bools. Working on that now. It would carve out primitive types as having value semantics. |
Yeah. I didn't look into all the details yet, but I like the idea of having value- and pointer- semantics for different types. It was long time ago, but I'm pretty sure I tried value-sematics when I was working on the first version for an obvious performance reason. Then I had to decide on pointers for a couple of reasons that I don't remember, unfortunately. Maybe I failed because I used value sematics for all types. Not sure. |
updated with bools. I wouldn't be entirely surprised if value semantics for non-primitive types did worsen the performance. I'm happy to look into it whenever there is time (which there rarely is tbh), but for now I think this offers an improvement that's worth adding. |
Also I would suggest that we create |
and maybe update the performance benchmark in README too? :) |
Fair enough to use pointer semantics for arrays and maps, but in Go strings also have value semantics. I wonder if that would also work in Tengo? |
Improves BinaryOp performance significantly
Before:
After: