8000 Optimize `ZIO.fail` by kyri-petrou · Pull Request #9487 · zio/zio · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Optimize ZIO.fail #9487

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

Merged
merged 5 commits into from
Jan 22, 2025
Merged

Optimize ZIO.fail #9487

merged 5 commits into from
Jan 22, 2025

Conversation

kyri-petrou
Copy link
Contributor

ZIO.fail is commonly used not only for raising errors, but also as shortcut (e.g., ZIO.fail(None)). While we're trying to use Exit.fail as much as possible when we need to shortcut, there are still quite a lot of usages of ZIO.fail both within the core zio repo and in zio-* libraries.

This PR optimizes ZIO.fail so that we get all the info we need to build the failure with 2 iterations of the runloop instead of 4

Copy link
Collaborator
@hearnadam hearnadam left a comment

Choose a reason for hiding this comment

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

Nice work! Seems like a good win.

val builder = stackTraceBuilderPool.get()

val stack = _stack
val size = _stackSize // racy

builder += _lastTrace
Copy link
Collaborator

Choose a reason for hiding this comment

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

Was this missing from the trace before? Do we have any tests for trace generation?

Copy link
Contributor Author
@kyri-petrou kyri-petrou Jan 22, 2025

Choose a reason for hiding this comment

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

It wasn't missing, but because earlier we were going deeper into the runloop stack this would be present in the stack itself. Now since the invocation is flat we have to add it.

Do we have any tests for trace generation

Yes a test failed after updating the code and the fix was to add this here

@kyri-petrou kyri-petrou merged commit 930ac6e into zio:series/2.x Jan 22, 2025
18 checks passed
@kyri-petrou kyri-petrou deleted the optimize-zio-fail branch January 22, 2025 13:04
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.

2 participants
0