-
Couldn't load subscription status.
- Fork 1.4k
Optimize error path in FiberRuntime
#9975
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimize error path in FiberRuntime
#9975
Conversation
| } | ||
|
|
||
| case updateFlags: ZIO.UpdateRuntimeFlags => | ||
| cur = patchRuntimeFlags(updateFlags.update, cause, null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would have previously:
- Allocated an
Exit.Failureunnecessarily - Set
cur = Exit.Failure(cause)which means we would have to exit the inner loop (due to thecur ne nullcondition), only so that we would do another loop of the outer loop to end back at theExit.Failurecase
| val size = _stackSize // racy | ||
|
|
||
| builder += _lastTrace | ||
| var last = _lastTrace |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Much more performant to keep the last variable in the stack memory instead of checking it in StackTraceBuilder which kept it in the heap
| private def patchRuntimeFlags[R, E0, A0]( | ||
| patch: RuntimeFlags.Patch, | ||
| cause: Cause[E0], | ||
| continueEffect: ZIO[R, E0, A0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this only used with Exit? Maybe we should make the types show that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeap, good point, changed 👍
| builder += id.location // TODO: Allow parent traces? | ||
| val loc = id.location | ||
| if (loc ne last) | ||
| builder += id.location // TODO: Allow parent traces? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| builder += id.location // TODO: Allow parent traces? | |
| builder += loc // TODO: Allow parent traces? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, thanks!
Two minor optimizations in this PR:
lastvariable when de-dupping traces in stack memory instead of the heap.Exit.Failure(see comment below)