Skip to content
Open
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 @@ -101,7 +101,7 @@ public static AgentScope getAndClearThreadLocalScope(Runnable task) {
return null;
}
AgentScope scope = threadLocalScope.get();
threadLocalScope.set(null);
threadLocalScope.remove();
Copy link
Contributor

@mcculls mcculls Nov 3, 2025

Choose a reason for hiding this comment

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

IIRC the reason for calling set(null) here rather than remove was for performance reasons.

If we assume that the thread will activate another scope later on, it is better to leave the entry in the thread-local's map rather than continually grow and shrink the underlying map. TBH it would be even better to use a holder pattern here, and avoid any mutating of the thread-local once setup.

So please don't merge this for now - I'll put together a quick benchmark to demonstrate the difference.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @mcculls! Your explanation is totally make sense. If benchmark will show that set(null) is better I will change my PR to put a comment why we have set(null).

return scope;
}

Expand Down
Loading