-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Avoid lazy local contexts #9590
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
Conversation
These cause allocation of a LazyRef. It's better to use inContext, which is an inline function that gives better code.
test performance please |
performance test scheduled: 3 job(s) in queue, 1 running. |
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.
LGTM
goIdent(tree, start) | ||
inContext(prepIdent(tree, start)(using outerCtx)) { | ||
goIdent(tree, start) | ||
} |
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.
A digression: the pattern seems to suggest a useful addition to stdlib:
inline def use[T, U](o: T)(inline op: o.type ?=> U): U = op(using o)
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.
Yes, I agree.
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.
If we think in that direction, it seems use
can be used to replace given
for some use cases:
val ctxInner = prepIdent(tree, start)(using outerCtx)
use ctxInner:
goIdent(tree, start)
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.
yes, but InContext is a bit clearer for reading, I think.
performance test failed: Please check http://lamppc37.epfl.ch:8000/pull-9590-08-19-20.50.out for more information |
These cause allocation of a LazyRef. It's better to use inContext,
which is an inline function that gives better code.