Repository navigation
ariadne: the state imports and the volume writers (G1, eighth part) - #1135
Merged
Merged
Conversation
A guest reached state only through call, which ends its slice for the activation's loop to make the call: a round trip of the loop's own steps per value read or written. ScriptSlice::call_now is a fast path beside call(). It calls a function the lane holds as a native, the one call() would reach in the same environment and under the same narrowing, inside the slice, which goes on. Its deep-data work runs to its end there, and what it raises is the reply. A name the lane holds otherwise (a document function) is left to call(). The wasm engine's state imports go through it: state_get, state_exists, state_children, state_data_get, state_set, state_data_set, state_delete, state_swap, state_incr and state_cas, each the path as text and its values as CBOR, a step a call. imports: narrowed state- functions on their names, so the atomics and the expiry setters counted as state.read; the writers are now listed, and are state.write's. The writers of section 8.4.1 come with the data.write group. volume_write writes a box into the guest's own copy of a volume: one anyone else may hold is copied at its first write, and the handle names the copy, so nothing else changes until the guest stores it with state_data_set. One only the guest holds is written in place. volume_new makes a volume from data_info's map (dims, voxel, bounds), counted against the call's allocation limit, and returns its handle, which is now always positive as an i64. AFailedEventLetsTheNextOneGo drains until both events are in: one drain could leave the second to the next frame once the 8 ms frame budget was spent on a slow first run.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
G1, eighth part: a guest's state imports, a fast path beside
call, and §8.4.1's volume writers (roadmap §8.4, §8.4.1, §8.6).The problem
call. A guest reached state only throughcall, which ends the guest's slice so the activation's loop can make the call. So every value read or written cost a round trip through the loop's own steps.imports:miscounted writers.imports:sorted thestate-functions into groups by name. Sostate-cas,state-swap,state-incrand the expiry setters counted asstate.read, andimports: [state.read]let a guest write through them.volume_write,volume_new) weren't there.The fix
A fast path beside
call.ScriptSlice::call_now(function, args):call()would reach, in the same environment, so the chroot, thelink:holes andmay_callall apply;call()'s reply would arrive. An interruption is thrown.A name the lane holds otherwise (a document function, say) gets false back, and goes through
call(). The fast path belongs to the core, so any engine can use it.The state imports. Each one calls one of the lane's state natives through
call_now:state_getstate-getstate_existsstate-existsstate_childrenstate-childrenstate_data_getstate-data-getstate_setstate-setstate_data_setstate-data-setstate_deletestate-deletestate_swapstate-swapstate_incrstate-incrstate_casstate-casstate_incrdelta means 1.calldoes, and costs a step.GuestCallpolls the call again in the same slice until the slice's budget is spent.state.writelists its writers. They arestate-set,state-set-tree,state-data-set,state-from-json,state-delete,state-cas,state-swap,state-incr,state-expire,state-expire-at,state-clear-expiryandstate-sweep-expired. Every otherstate-function isstate.read's. This applies tocalland the state imports alike.The volume writers, with the
data.writegroup:volume_write(h, x, y, z, nx, ny, nz, src, len)writes a box into the guest's own copy of the volume.state_data_set.volume_new(spec, len)makes a zeroed volume from a CBOR map asdata_infogives one (dims,voxel,bounds).Docs
script_engine.h(call_now) andwasm_engine.h(the state imports, the writers,state.write).Tests
ariadne_wasm_test, new:TheStateImportsAreTheLanesStateFunctions: set, incr, get, cas, swap, children, exists and delete, all under the document's prefix.ImportsNarrowTheStateImports:[state.read]lets readers through and refusesstate_set,state_cas, andstate-incrthroughcall. With the old name-based grouping put back, it fails.AStateImportCostsAStepWhereACallEndsTheSlice: 500 increments through the import fit under a 3000-step action cap; throughcallthey don't. Withcall_nowmade to always decline (every state import then goes throughcall), this test fails alone and the other state tests pass, so the fallback works too.AGuestWritesItsOwnCopyOfAVolume:TheWritersRefuseWhatTheyCantDo: refusals for nodata.write(PermissionError), past the allocation limit (MemoryError) and an unknown voxel type (ValueError).ariadne_script_engine_test:AFailedEventLetsTheNextOneGo(#1129's) drains until both events are in, at most 10 drains. It asserted one drain, and failed once here when a slow first run spent the 8 ms frame budget on the first event.Local, Windows static Release tree:
ariadne_wasm_test27/27,ariadne_script_engine_test30/30 andariadne_runtime_test262/262, three runs each.arix_wasm_blockandari_wasm_needs_arixctests.git clang-format --diffagainst the merge base): clean.Left for G1
state_exec.policy, andpureexports on the read lane.arix/ariglxrecipes.