Skip to content
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

avoid core.eval for error handling #373

Merged
merged 2 commits into from
May 16, 2024
Merged

avoid core.eval for error handling #373

merged 2 commits into from
May 16, 2024

Conversation

fwbrasil
Copy link
Collaborator

This is the main cause of the regression in #347. The eval method introduces much more overhead than the previous dedicated loop. The issue is that function applications don't get inlined and producing a thunk to provide to resume introduces more indirection, preventing JIT optimizations.

I'll post benchmark results tomorrow.

Comment on lines 40 to 42
case ex if NonFatal(ex) =>
Failure(ex)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

There is no longer a need to match on NonFatal here - that's already checked in the loop.

Comment on lines +124 to +128
try
catchingLoop(v)
catch
case ex: Throwable if (NonFatal(ex) && pf.isDefinedAt(ex)) =>
pf(ex)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This outer try/catch appears unnecessary if you make v a function, but from the description that seems intentional.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's placed to catch exceptions in the evaluation of the v thunk since it's a by-name parameter. Making it a no-arg function is equivalent to a by-name param in the generated bytecode and we'd still need to evaluate the function to decide if it's necessary to suspend or not (catchingLoop). Although these two catches seem close in the method, they're placed in very different execution paths, which is helpful to specialize the code for JIT compilation. This seems the key characteristic that enables the better performance in comparison to eval, which was making the execution become much more dynamic.

@hearnadam hearnadam merged commit 786a79c into main May 16, 2024
3 checks passed
@fwbrasil fwbrasil deleted the eval-catching branch May 16, 2024 15:34
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.

None yet

2 participants