Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@kyri-petrou
Copy link
Contributor

Two minor optimizations in this PR:

  1. Keep last variable when de-dupping traces in stack memory instead of the heap.
  2. Avoid exiting the inner loop when popping continuations in case of an Exit.Failure (see comment below)

@kyri-petrou kyri-petrou requested a review from hearnadam June 16, 2025 05:22
}

case updateFlags: ZIO.UpdateRuntimeFlags =>
cur = patchRuntimeFlags(updateFlags.update, cause, null)
Copy link
Contributor Author

@kyri-petrou kyri-petrou Jun 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would have previously:

  1. Allocated an Exit.Failure unnecessarily
  2. Set cur = Exit.Failure(cause) which means we would have to exit the inner loop (due to the cur ne null condition), only so that we would do another loop of the outer loop to end back at the Exit.Failure case

val size = _stackSize // racy

builder += _lastTrace
var last = _lastTrace
Copy link
Contributor Author

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

hearnadam
hearnadam previously approved these changes Jun 16, 2025
private def patchRuntimeFlags[R, E0, A0](
patch: RuntimeFlags.Patch,
cause: Cause[E0],
continueEffect: ZIO[R, E0, A0]
Copy link
Collaborator

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.

Copy link
Contributor Author

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?
Copy link
Member

@guizmaii guizmaii Jun 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
builder += id.location // TODO: Allow parent traces?
builder += loc // TODO: Allow parent traces?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, thanks!

@kyri-petrou kyri-petrou merged commit 5c02ff1 into zio:series/2.x Jun 19, 2025
19 checks passed
@kyri-petrou kyri-petrou deleted the optimize-error-path-fiber-runtime branch June 19, 2025 05:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants