Closed Pieter12345 closed 1 year ago
Maybe just do this in clone() instead.
if(clone.stackTraceManagerThread != Thread.currentThread()) {
clone.stackTraceManagerThread = Thread.currentThread();
clone.stackTraceManager = new StackTraceManager();
}
Then we can have instantiation like:
private Thread stackTraceManagerThread = Thread.currentThread();
private StackTraceManager stackTraceManager = new StackTraceManager();
and have GetStackTraceManager() just return stackTraceManager.
In this case, I think moving the order around in CClosure would replace <<main code>>
with <<closure>>
at the start of a stacktrace on a new thread.
Maybe just do this in clone() instead.
if(clone.stackTraceManagerThread != Thread.currentThread()) { clone.stackTraceManagerThread = Thread.currentThread(); clone.stackTraceManager = new StackTraceManager(); }
Then we can have instantiation like:
private Thread stackTraceManagerThread = Thread.currentThread(); private StackTraceManager stackTraceManager = new StackTraceManager();
and have GetStackTraceManager() just return stackTraceManager.
In this case, I think moving the order around in CClosure would replace
<<main code>>
with<<closure>>
at the start of a stacktrace on a new thread.
Doing that does have the benefit of not needing to check two conditions in the getter, but it adds potential issues that will occur when first creating/cloning the environment and then using that environment on a new thread to execute code. I prefer not to require cloning the environment on the new thread to avoid having the wrong stacktrace manager in the environment.
If that were an issue, it would affect a lot of other things besides the StackTraceManager, and cloning on the new thread is already how things work. So I think it's unnecessary but harmless to approach it like you're doing. It solves the problem.
Store
StacktTraceManager
directly inGlobalEnv
to prevent a synchronized hashmap lookup on everyeval()
andseval()
call. MoveStackTraceManager
getter inCClosure
to post-environment-clone to ensure that it does not overwrite theStackTraceManager
of the original thread when called from a new thread(by for examplex_new_thread()
).In the 5 seconds profile below, we can see that a couple of
GlobalEnv.GetStackTraceManager()
calls take up about 18% CPU time for my specific MethodScript program.