[Performance] Run refresh work in the existing force runner - #5039
[Performance] Run refresh work in the existing force runner#5039soulomoon wants to merge 7 commits into
Conversation
|
here is the perf report from codex gather from the pipeline:
|
crtschin
left a comment
There was a problem hiding this comment.
Nice! The code looks correct to me, but this is a bit subtle so it would be nice to improve the docs a bit while we're here.
| refresh db stack key result = case (addStack key stack, result) of | ||
| (Left e, _) -> throw e | ||
| (Right stack, Just me@Result{resultDeps = ResultDeps deps}) -> asyncWithCleanUp $ refreshDeps mempty db stack key me (reverse deps) | ||
| (Right stack, Just me@Result{resultDeps = ResultDeps deps}) -> refreshDeps mempty db stack key me (reverse deps) |
There was a problem hiding this comment.
The comment above refreshDeps still refers to this spawn, mind updating the comment?
There was a problem hiding this comment.
The builder would create a new thread for its deps ?
perhaps change it to Otherwise, new threads would be created to refresh the dirty deps (if any) and then compute the key itself in current thread ? WDYT
|
|
||
| -- | Refresh a key: | ||
| refresh :: Database -> Stack -> Key -> Maybe Result -> AIO (IO Result) | ||
| -- | Refresh a key in the existing force runner, which already owns its lifetime. |
There was a problem hiding this comment.
Could you elaborate this comment a bit, maybe write a Note about the ownership model?
See if you agree with how I read this currently:
- A force runner refers to the first thread that evaluates the rule thunk in the database.
- Refreshing refers to checking whether any dependencies changed and the key needs to be recomputed.
- If a session restart occurs while a thread is refreshing a key, this is safe as the shake database increment invalidates outdated values as well.
There was a problem hiding this comment.
- By design,
builderfind out the rule is still Dirty and wrap it intoSpawn(IfRunning, just wrap it intoWait) and then waitConcurrently_ create its force runner and run it. - yes
- If session restart interrupt the proccess, since the step incre and the next run would consider it as
Dirtyagain even though theRunningstate would not be altered. seeviewDirty.
There was a problem hiding this comment.
Do we have an existing note that captures this? If not, could you write one that explains how invalidation is structured and the invariants that hold?
There was a problem hiding this comment.
added. feel free to update the note if there is any problem there
Run refresh work directly in the existing force runner, removing the redundant
asyncWithCleanUplayer and its extra async registration and wait. Notice we already havedata Waitto handle possible thread spawning. We have 5% perf improvement with this simple deletion