Repository navigation
Optimizations - #77
Open
gaymeowing wants to merge 19 commits into
Open
gaymeowing wants to merge 19 commits into
gaymeowing wants to merge 19 commits into
Conversation
* add fluid.dev() to toggle dev mode, replacing the graph's hardcoded dev_mode flag and _G.__DEV__ * remove types/globals.d.luau and its definition file setting * unit tests run with dev mode enabled
* render callbacks run on reused runner threads instead of task.spawn creating a thread for each one, a callback that yields keeps its thread and a new one gets created for the rest * type scheduler's cancel, since coroutine.close has returns and task.cancel doesn't * add a test for a yielding callback not stalling the others
* for_keys keeps keys whose value is false, instead of destroying and recreating them every update
* store node kind and state as bitflags (EAGER/DEFERRED/LAZY/ASYNC in the low bits, RUNNING/DIRTY/DEAD above them), instead of the evaluation & state strings * replace the evaluation string enum with graph.evaluation * add EffectNode for nodes that no other node depends on (effects, deferred, tags) * add graph.refresh_node, which brings a node up to date without tracking it as a dependency * dependency edges store their position in the other node's array as u16 slots in buffers, so they're removed in O(1) * reads are matched against the last run's dependencies by position, so edges read in the same order get kept instead of being removed and re-added every run * reading the same node multiple times in one run only adds one edge * children are removed from their parent in O(1) through child_index * children and cleanups start as a shared frozen empty table until the first one is added * cleanups store values as is (functions, threads, connections, instances, objects) instead of wrapping each one in a closure, cleanup.luau only cleans up a value now and fluid.cleanup is defined in init.luau, since the graph requires cleanup * threads passed to fluid.cleanup get cancelled through scheduler.cancel * only lazy nodes compare their result & bump last_evaluation, eager and deferred nodes are never read * track verified_at separately from last_evaluation, fixes nodes dropping a dependency on a dirty derive that reran without changing * nested invalidations only evaluate what they queued, fixes a stack overflow when many effects set sources in one invalidation * dirty dependencies of a pending node get evaluated on their own first, so an erroring dependency doesn't stop the node from running * erroring nodes are reported with logging.report_error instead of logging.warn * nodes whose dependency errored are marked clean, so they keep updating * destroyed nodes are marked dead so queued ones don't rerun, including nodes destroyed by their owner rerunning mid update * restore a node's effect after it errors inside untrack, fixes the node never running again * nodes destroyed by their own effect drop the dependencies they read afterwards * changes made while a node is running still count as newer than its run * reading a node mid evaluation returns its cached value instead of erroring * is_similar checks == first * yield checks and the self dependency assert only run in dev mode, outside of it functions run on the caller's thread through xpcall * run_as_unsafe hardcodes 2 returns instead of passing a varadic through * rename processing_node to processing_nodes as to better reflect the fact its a hash map that holds multiple nodes * processing_nodes is weak, so threads that errored or got cancelled can be collected * flush_deferred_nodes is passed to scheduler.defer directly instead of a closure * assert_scope returns Node<T> * effect & deferred create effect nodes, derive caches evaluate_node, tags pushes its cleanup straight to the graph
* bind now sets the Parent property last * bind connects events after the properties are set, so handlers don't fire for the initial values * bind & changed push connections as cleanups directly instead of wrapping them in a closure * bind skips reading properties for values that aren't functions, since only functions can be event handlers * property bindings & reactive children create effect nodes * reactive children store their instance, function & children in one record so their effect isn't a closure, with children tracked using an update id instead of swapping 2 sets * an instance that's in a reactive child's result more than once only gets parented once
* root runs fn through a packing function instead of creating a closure every call, and passes false as the parent when there's no scope * source checks how many args it got inline instead of through get_argument_from, and caches the graph functions it calls
* switch_delay's destroy functions are at the file scope instead of being closures created for every switch * switch_delay builds its result array when it updates instead of on every read, reads return a copy so consumers mutating it don't change the actual values
* interval only checks for yields in dev mode, otherwise it calls its function with xpcall on the caller's thread instead of creating a thread every tick * hoist interval's silent yield handler instead of creating a closure every failing tick, and cache 1 / hz * remove reactive_fn_calls.call, it was just an unused xpcall wrapper * add a test for interval running on the caller's thread outside dev mode
…loop if its given a negative value
This branch has not been deployed
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.
graph
evaluationandstatestring enums; usages of theevaluationstring enum are now replaced with references tograph.evaluation.@nativesourceSlots/observerSlotslink()_depGenchild_indexchildrenandcleanupsshare a frozen empty table until the first one is addedEffectNodefor nodes nothing reads (effects, deferred, bindings, reactive children, tags), which skips the dependents fieldsis_similarchecks==firstpending_evalhas its length tracked via an upvalueprocessing_nodesis weak so that dead threads don't get kept aroundthreads
intervalnow only runs its callback on a separate thread in dev modeinstances
bindsets.Parentlastbindconnects events after properties are set, so handlers don't fire for the initial values (taken from vide)createcaches one constructor per class and no longer wrapsInstance.new()in apcall()misc
root,sourceandswitch_delayswitch_delaybuilds its result array when it updates instead of on every readfor_valuesno longer invalidates its own node fromdestroylerpusesvector.lerp()for vectorsfluid.dev()instead of_G.__DEV__, and yields in effects and intervals are only caught in dev modelogging.report_errorinstead of being warnedbug fixes
for_keysdestroyed and recreated keys whose value wasfalseon every update:readers lost their dependency on a derive that was dirty but didn't change, so they stopped updating:
many effects writing sources in one update causes a stack overflow:
destroyed nodes kept rerunning with stale values, and more of them piled up every time their owner reran:
nodes that errored inside
untracksilently never ran again:effects that read a derive mid evaluation kept the derive's stale value:
behavior changes
fluid.dev()instead of_G.__DEV__, with yields in effects and intervals only caught in dev modelogging.report_errorinstead of using warntooling
convert_unitslooping forever on negative values