Comments (7)
Awesome! Can you create PR for this? If you also can provide a benchmark, it will be really interesting to see the performance increase.
from expr.
PR #54
Only a ~10000x performance improvement on my contrived example : )
from expr.
I actually realized this problem is a general pattern in the runtime code. There is a difference between a reflect.Value and putting that value into an interface, a reflect.Value is a way of accessing the pre-existing memory, where putting something into an interface is going to make a copy.
So another example in the code, if you have an embedded struct:
type Foo struct {
Bar struct {
Field int
}
}
When you do 'Bar.Field', fetch will return a copy of Bar, not a pointer to the original Bar. So if we do something like my previous example and stick a big chunk of memory in the Bar structure, it's going to value copy all of Bar. Now that can be pretty easily fixed in the case of above (when Run() was called with an environment as a pointer), because then Bar's value will be addressable (CanAddr() is true) and you could create an interface of (type, *Bar) instead of (type, Bar) by returning value.Addr() instead of value. But I didn't look how it would work for other types, I guess slices are fine since the slice itself can be value copied (and what the slice points to isn't copy), but for fixed sized arrays, etc, I imagine the code now will value copy the entire array for an index operation like 'a[0]'. The additional problem is CanAddr() will be false if you passed a value to Run() instead of a pointer, but at least this is something callers can easily control.
Basically I feel like it should be a principle of expr (for a few important reasons) to be zero-copy of the environment (when a caller calls Run() with a value and not a pointer, they create a copy at their callsite of course, but that doesn't really have anything to do with expr). Right now it seems like expr is copying all over the place.
from expr.
I tried making a patch for this but it's actually a bit harder than it seems, because I thought perhaps I could just return a *struct and a slice instead of an array in fetch(), but then the problem comes to method/functions calls when the arguments are pointers and they expected values, etc, and it seems pretty ugly to try to map that back at call sites, etc. I think the real solution is probably working in reflect.Value's instead of interface{}.
from expr.
See #56
from expr.
I think the real solution is probably working in reflect.Value's instead of interface{}.
I also was thinking about it.
from expr.
Easiest thing to do without a big change is just allow to opt in to the zero copy behaviour
from expr.
Related Issues (20)
- Floating number comparison returns incorrect result HOT 1
- Parentheses disappear for conditional node HOT 3
- EOL for pmezard/go-difflib dependency HOT 2
- Logical operation against array functions not working as expected in v1.16 HOT 2
- Estimated expression cost
- Comparison with named integer type fails HOT 1
- OSS-Fuzz issue 68580
- Checker infinit looping when using patcher/value and operator overloading HOT 5
- Extra type hints for maps content? HOT 3
- Double escaping pair node key
- OSS-Fuzz issue 68797
- OSS-Fuzz issue 68824 HOT 1
- fromPairs does not work HOT 1
- Implement `int*` and `uint*` builtin functinos HOT 2
- pygments lexer support for mkdocs highlighting HOT 1
- Add uniq() builtin HOT 2
- Feature Request: Types implementing "fmt.Stringer" should be assignable/comparable to strings HOT 4
- interface conversion: interface {} is nil, not string (1:9) HOT 5
- Overflow errors when building for `386` HOT 2
- Can expr support custom function? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from expr.