Skip to content

Commit

Permalink
LDEV-5021 - improve performance cloning PageContext
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeloffner committed Jul 16, 2024
1 parent d292579 commit 400e64a
Showing 1 changed file with 50 additions and 14 deletions.
64 changes: 50 additions & 14 deletions core/src/main/java/lucee/runtime/PageContextImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -487,8 +487,9 @@ public PageContextImpl initialize(HttpServlet servlet, HttpServletRequest req, H
if (clone) {
this.cfid = tmplPC.cfid;
this.client = tmplPC.client;
// this.cgiR = tmplPC.cgiR;
// this.cgiRW = tmplPC.cgiRW;
this.session = tmplPC.session;
this.cgiR = tmplPC.cgiR;
this.cgiRW = tmplPC.cgiRW;
this.cookie = tmplPC.cookie;
this.form = tmplPC.form;
this.url = tmplPC.url;
Expand Down Expand Up @@ -621,22 +622,24 @@ public void release() {
caller = null;
callerTemplate = null;
root = null;
// Attention have to be before close
if (client != null) {
client.touchAfterRequest(this);
client = null;
}

if (session != null) {
session.touchAfterRequest(this);
session = null;
}

// ORM
// if(ormSession!=null)releaseORM();

// Scopes
if (hasFamily) {
boolean lastStanding = lastStanding();
// Attention have to be before close
if (client != null) {
if (lastStanding) client.touchAfterRequest(this);
client = null;
}

if (session != null) {
if (lastStanding) session.touchAfterRequest(this);
session = null;
}

if (hasFamily && !isChild) {
req.disconnect(this);
}
Expand All @@ -655,8 +658,22 @@ public void release() {
threads = null;
allThreads = null;
currentThread = null;
cgiR = new CGIImplReadOnly();
cgiRW = new CGIImpl();
}
else {

// Attention have to be before close
if (client != null) {
client.touchAfterRequest(this);
client = null;
}

if (session != null) {
session.touchAfterRequest(this);
session = null;
}

close();
base = null;
if (variables.isBind()) {
Expand All @@ -670,9 +687,9 @@ public void release() {
undefined.release(this);
urlForm.release(this);
request.release(this);
cgiR.release(this);
cgiRW.release(this);
}
cgiR.release(this);
cgiRW.release(this);
argument.release(this);
local = localUnsupportedScope;

Expand Down Expand Up @@ -753,6 +770,25 @@ public void release() {
catch (Exception e) {
}
}
startTime = 0L;
}

private boolean lastStanding() {
if (!hasFamily()) return true;
// active childern?
Queue<PageContext> tmp = this.children;
if (tmp != null) {
for (PageContext p: tmp) {
if (p.getStartTime() > 0) return false;
}
}
// active parent?
PageContext p = this;
while ((p = p.getParentPageContext()) != null) {
if (p.getStartTime() > 0) return false;
}

return false;
}

private void releaseORM() throws PageException {
Expand Down

0 comments on commit 400e64a

Please sign in to comment.