near / react-on-chain

Improved execution layer for NEAR decentralized frontend components
https://roc-docs.near.dev/
23 stars 5 forks source link

Optimize sandboxed Component fetches #381

Open andy-haynes opened 1 month ago

andy-haynes commented 1 month ago

When the compiler statically analyzes Component children, it ignores untrusted renders since they get evaluated at runtime. If the path of these sandboxed child Components are known at parent bundle time however, the compiler could warm the cache by requesting the source for these children after it finishes servicing the current request.

This fetching would occur in the worker context while the parent's initial render plays out, reducing wait time for the subsequent compiler request of the sandboxed children. Note that this works same regardless of whether or not the preemptive fetch has completed by the time the child is requested.

E.g.

this.sendWorkerMessage(...);

// `sandboxedChildComponents` is the set of all sandboxed Components
// rendered as children of any of this container's Components
this.getComponentSources(sandboxedChildComponents);