-
Notifications
You must be signed in to change notification settings - Fork 79
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
More consistent ownership #150
Comments
Generally, the driving factors for returning ownership were whether the accessed information will still be needed by the callee, and whether it will typically be accessed repeatedly. For type structures, the assumption is that they all are transparent, traversable, (usually) tree-shaped type descriptions with a canonical parent-owns-children policy. So constructors all take ownership and accessor to such a structure are meant for efficient reading/traversal. Passing back ownership would require costly copying subgraphs for every read node, where a vector is just a particular kind of a node. That would imply a quadratic amount copying when traversing a deeper tree. Or a complicated internal ownership regime. (Mind you, we don't have much type structure yet, but more will come and the design should be future-proof.) Something like It is true that we could use iterators to access vectors, but they require additional state and are more complex and costly than just returning a pointer, when the information is stored in array form anyway. Another option would be to have indexed accessors -- that's simpler but probably still more costly. It also seems easier (and possibly requires fewer allocations) for higher-level bindings if input/output is handled symmetrically, i.e., uses a uniform abstraction for representing vectors of things and use both ways -- they can just wrap this abstraction. But that is just a conjecture. |
Following up on this to say that we're experiencing a similar issue on two fronts:
I'd like to add that the comment in wasm.h about how
Speaking for myself, I see the Wasm C API as a very generic API designed to work on all different types of Wasm VMs, so the right trade off in my mind is to always prioritize universality over performance. Though usability is also an important consideration. For example, interacting with either imports or exports by name is a pretty complicated process in the current Wasm C API that requires building up your own data structures and organizing the data yourself when the same thing could be done more efficiently and directly by most hosts by providing a higher level function in the C API. I think this is a fine tradeoff to make, having a universal API could be really valuable. But it does lead me to believe that a C library built on top of the Wasm C API that provides a higher level interface would be the right choice for most users. Those higher level features could always be added into wasm.h too, as is already done with things like On the other hand, being too slow could lead to more fragmentation. But most use cases I've seen personally are completely dominated by the Wasm compilation and execution time. As long as the critical paths (i.e. calling functions, loading cached modules) aren't too slow, I think it's actually not important if the rest of the C API is slow or inefficient. But it does matter if it's easy to implement and use correctly (and also easy for end-users to build things with). |
Original comments by @alexcrichton in #145 (comment) :
And #145 (comment) :
The text was updated successfully, but these errors were encountered: