Skip to content

Commit

Permalink
don't "re-get" some scopes if they don't change across frames
Browse files Browse the repository at this point in the history
  • Loading branch information
softwareCobbler committed Nov 23, 2024
1 parent 84d5ba6 commit 033a2e4
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
13 changes: 12 additions & 1 deletion luceedebug/src/main/java/luceedebug/coreinject/DebugManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import luceedebug.IDebugManager;
import luceedebug.coreinject.frame.DebugFrame;
import luceedebug.coreinject.frame.Frame;
import luceedebug.coreinject.frame.Frame.FrameContext;

public class DebugManager implements IDebugManager {

Expand Down Expand Up @@ -699,7 +700,17 @@ private DebugFrame maybe_pushCfFrame_worker(PageContext pageContext, String sour

final int depth = stack.size(); // first frame is frame 0, and prior to pushing the first frame the stack is length 0; next frame is frame 1, and prior to pushing it the stack is of length 1, ...

final DebugFrame frame = DebugFrame.makeFrame(sourceFilePath, depth, valTracker, pageContext);
FrameContext maybeBaseFrame = stack.size() == 0
? null
: stack.get(0) instanceof Frame ? ((Frame)stack.get(0)).getFrameContext() : null;

final DebugFrame frame = DebugFrame.makeFrame(
sourceFilePath,
depth,
valTracker,
pageContext,
maybeBaseFrame
);

stack.add(frame);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import lucee.runtime.PageContext;
import luceedebug.IDebugFrame;
import luceedebug.coreinject.ValTracker;
import luceedebug.coreinject.frame.Frame.FrameContext;

/**
* Should be a sealed class, subtypes are:
Expand All @@ -19,14 +20,14 @@ public abstract class DebugFrame implements IDebugFrame {
// and if so, we just return some dummy frame which is guranteed to NOT schedule more work.
static private ThreadLocal<Boolean> isPushingFrame = ThreadLocal.withInitial(() -> false);

static public DebugFrame makeFrame(String sourceFilePath, int depth, ValTracker valTracker, PageContext pageContext) {
static public DebugFrame makeFrame(String sourceFilePath, int depth, ValTracker valTracker, PageContext pageContext, FrameContext root) {
if (isPushingFrame.get()) {
return DummyFrame.get();
}
else {
try {
isPushingFrame.set(true);
return new Frame(sourceFilePath, depth, valTracker, pageContext);
return new Frame(sourceFilePath, depth, valTracker, pageContext, root);
}
finally {
isPushingFrame.set(false);
Expand Down
22 changes: 11 additions & 11 deletions luceedebug/src/main/java/luceedebug/coreinject/frame/Frame.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,16 @@ public static class FrameContext {
// expensive exceptions on literally every frame, e.g. if a scope is disabled by the engine and trying to touch it
// throws an ExpressionException.
//
private FrameContext(PageContext pageContext) {
private FrameContext(PageContext pageContext, FrameContext root) {
this.pageContext = pageContext;
this.application = getScopelikeOrNull(() -> pageContext.applicationScope());
this.application = root != null ? root.application : getScopelikeOrNull(() -> pageContext.applicationScope());
this.arguments = getScopelikeOrNull(() -> pageContext.argumentsScope());
this.form = getScopelikeOrNull(() -> pageContext.formScope());
this.form = root != null ? root.form : getScopelikeOrNull(() -> pageContext.formScope());
this.local = getScopelikeOrNull(() -> pageContext.localScope());
this.request = getScopelikeOrNull(() -> pageContext.requestScope());
this.session = getScopelikeOrNull(() -> pageContext.getApplicationContext().isSetSessionManagement() ? pageContext.sessionScope() : null);
this.server = getScopelikeOrNull(() -> pageContext.serverScope());
this.url = getScopelikeOrNull(() -> pageContext.urlScope());
this.request = root != null ? root.request : getScopelikeOrNull(() -> pageContext.requestScope());
this.session = root != null ? root.session : getScopelikeOrNull(() -> pageContext.getApplicationContext().isSetSessionManagement() ? pageContext.sessionScope() : null);
this.server = root != null ? root.server : getScopelikeOrNull(() -> pageContext.serverScope());
this.url = root != null ? root.url : getScopelikeOrNull(() -> pageContext.urlScope());
this.variables = getScopelikeOrNull(() -> pageContext.variablesScope());
this.this_ = getScopelikeOrNull(() -> {
// there is also `PageContextImpl.thisGet()` but it can create a `this` property on the variables scope, which seems like
Expand Down Expand Up @@ -222,12 +222,12 @@ public <T> T doWorkInThisFrame(Supplier<T> f) {
}
}

Frame(String sourceFilePath, int depth, ValTracker valTracker, PageContext pageContext) {
this(sourceFilePath, depth, valTracker, pageContext, Frame.tryGetFrameName(pageContext));
Frame(String sourceFilePath, int depth, ValTracker valTracker, PageContext pageContext, FrameContext root) {
this(sourceFilePath, depth, valTracker, pageContext, Frame.tryGetFrameName(pageContext), root);
}

private Frame(String sourceFilePath, int depth, ValTracker valTracker, PageContext pageContext, String name) {
this.frameContext_ = new FrameContext(pageContext);
private Frame(String sourceFilePath, int depth, ValTracker valTracker, PageContext pageContext, String name, FrameContext root) {
this.frameContext_ = new FrameContext(pageContext, root);
this.sourceFilePath = Objects.requireNonNull(sourceFilePath);
this.valTracker = Objects.requireNonNull(valTracker);
this.id = nextId.incrementAndGet();
Expand Down

0 comments on commit 033a2e4

Please sign in to comment.