Description
I found a way to make everything but the variable get fast in this comment, and that one remaining optimization looks an awful lot like the inline caches used for types. The fallback path is about the only part that isn't a trivially inlined function.
And for semantics, there's concerns about excessive creation of async variables, and I do share them: #50
One way to quietly guide people to use async vars correctly (and to optimize async var usage in general) is to make them literal variable bindings. Also, admittedly, .get()
is annoying boilerplate.
And for performance, this glides right in and makes it all both trivially tree-shakeable and essentially zero-cost.
So, what about this syntax?
The syntax here is intentionally somewhat anti-bikeshed. Concise enough to get the point across, but (especially for snapshots) ugly enough to move discussion along.
// Define one or more dynamic variable
dynamic foo = initialValue, bar = ...
// Get the variable's current value
let currentValue = foo
// Set a dynamic variable in a scope
// Automatically restored after exit
{
dynamic using foo = otherValue
dynamic using path.to.foo = otherValue
// ...
}
// Get a snapshot of the current state
// Semantically changes on dynamic set, but engines can amortize that
const snapshot = function.context
// Use snapshot
dynamic using * from snapshot
From a spec standpoint, this would be a unique type of reference, alongside property values. Module property accesses would return dynamic values as references to dynamic values.