This issue has been created
There are 2 updates.
 
 
XWiki Commons / cid:jira-generated-image-avatar-bd4a7f4e-a0ca-432c-9b97-28aa62b5fafd XCOMMONS-3909 Open

Getting the Velocity context copies again all the script bindings of the request

 
View issue   ยท   Add comment
 

Issue created

 
cid:jira-generated-image-avatar-541416d3-9c00-408e-8372-29ce2aa1ee56 Michael Hamann created this issue on 18/Nov/26 17:08
 
Summary: Getting the Velocity context copies again all the script bindings of the request
Issue Type: cid:jira-generated-image-avatar-bd4a7f4e-a0ca-432c-9b97-28aa62b5fafd Improvement
Affects Versions: 17.10.0
Assignee: Unassigned
Components: Velocity
Created: 18/Nov/26 17:08
Labels: performance
Priority: cid:jira-generated-image-static-major-90357a81-2f19-45ad-b523-094eb0d0a54c Major
Reporter: Michael Hamann
Description:

Every call to VelocityManager#getVelocityContext() re-synchronizes the request's Velocity context with the JSR-223 script context: ScriptVelocityContext#setScriptContext() copies all bindings of the global and engine scopes into the Velocity context. As ScriptVelocityContext#internalPut() writes every Velocity #set back into the engine scope, that scope contains every variable set by every template rendered so far in the request (237 on a simple page view of the standard flavor), and all of them are put again on each call although they are already there. Each put() interns the key (String.intern(), a native string table lookup), updates the map and writes the value back into the script context.

On a local profile of Sandbox.WebHome (standard flavor, master), getScriptVelocityContext() takes 14% of the request CPU, String.intern() alone ~10%. It is called for each template, Velocity macro, title, UI extension parameter and, through the Velocity fallback of icon themes, for each rendered icon.

Change

Skip the bindings whose value is already the one in the Velocity context. The remaining work per binding is a map lookup.

 
 

2 updates

 
cid:jira-generated-image-avatar-541416d3-9c00-408e-8372-29ce2aa1ee56 Changes by Michael Hamann on 18/Nov/26 17:11
 
Fix Version: 18.10.0-rc-1
Assignee: Michael Hamann