-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
wasm: clarify opa_eval args #3696
Comments
Sorry, those match the text, but the presentation there could surely be improved -- adding the types, we have:
The int32 is the length of the input string written to memory. Does that help?
That'll be |
I am getting somewhere but definitely doing something wrong in terms of what I need / no longer need to call... (old Evaluate is the method above, it mirros the JS impl) I am quite sure that something in the chain outlined via #3627 is wrong in my implementation because the unit test is failing (identical to Evaluate). |
I don't know how the C# wasm stuff works, but the idea is that you wouldn't even call |
A question on that code piece - there is a distinction in dumping between json (opa_json_dump) and value (opa_value_dump), however, on parsing it is always value parsing (opa_value_parse). Is this intentional? |
I modified as per your suggestions:
This makes it work... but sure feels strange to modify the heap in this "rude" fashion. Btw, what should _dataHeapPtr be after the evalution? (so a new call to FastEvaluate is working properly - reset to original to overwrite what was there, or end of 1st JSON?) |
Yeah, so, any JSON is a valid "Value" format -- the distinction between the two is sets, which don't exist in JSON. So,
would be a valid "value" string, but not valid JSON. When reading the input, however, it's up to the caller to provide JSON or "value". For the output, however, we let the caller decide: if they can make sense of "value" (sets in json), then they can have that; if they cannot, they get the JSON variant -- sets become arrays.
😄 It's certainly a bit of a rough fast path, I grant you that. Personally, I think any low-level memory management done from the outside (messing with the heap ptr etc) is crude, but it's the way we've taken for now. Maybe some ABI 2 will happen that is both elegant, and works, and doesn't require a dozen VM calls...? Ideas are welcome.
It should be be reset to original. If you put it at the end of the first JSON input, the next JSON input will be written after that, and the next after that, etc, and you'll eventually run out of memory on subsequent calls to |
ok, so my not modifying _dataHeapPtr is the correct approach then. |
I added benchmark results: christophwille/dotnet-opa-wasm#16 - note that this doesn't reuse the policy but create it new each time. So the general overhead eats up most gains. |
🎉 Thanks again for updating the SDK. I suppose this can be closed now? 🤔 |
Yes, unless want to use it to track docs improvements from this. |
😄 fair enough. Let's do that. |
While I'd love a full-blown, useful-for-more-than-just-docs WITX definition here, I'll look into making a small improvement for clarifying the arguments... 😄 |
@christophwille would be you be able to have a look at that PR? Your input would be appreciated! 😃 |
https://github.com/open-policy-agent/opa/blob/main/docs/content/wasm.md
str_addr opa_eval(addr, entrypoint_id, value_addr, str_addr, int32, addr, format)
The int32 is supposed to be?
Also a question on entrypoint_id: unless you call opa_eval_ctx_set_entrypoint the default is used for eval. So what is the "default value" for default entry point in this case?
The text was updated successfully, but these errors were encountered: