Skip to content

Notify listeners when the scope top changes after switching scope stacks #8797

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 1 commit into from
May 12, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,13 @@ private class ContinuableScopeState implements ScopeState {

@Override
public void activate() {
ContinuableScope oldScope = tlsScopeStack.get().top;
tlsScopeStack.set(localScopeStack);
ContinuableScope newScope = localScopeStack.top;
if (oldScope != newScope && newScope != null) {
newScope.beforeActivated();
Copy link
Collaborator

Choose a reason for hiding this comment

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

we call before and after on a row without doing anything in between. Can this be simplified ?

Copy link
Contributor Author

@mcculls mcculls May 12, 2025

Choose a reason for hiding this comment

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

There's a very subtle difference - beforeActivated calls the profiling integration, while afterActivated calls the registered listeners.

In one place in the code beforeActivated is called before changing the top value:

scope.beforeActivated();
if (top != null) {
stack.push(top);
} else {
onBecomeNonEmpty();
}
top = scope;
scope.afterActivated();

but in another part of the code, they are called at the same time after the top has changed:

curScope.beforeActivated();
curScope.afterActivated();

In terms of actual implementation the profiling integration is just clearing some caches, so there is flexibility here and this could all be done in one method as long as the profiling integration is always called first.

However since the profiling integration will need to be refactored to make it context-first, that's something I will do in a separate PR.

newScope.afterActivated();
}
}

@Override
Expand Down