Uploaded image for project: 'XWiki Commons'
  1. XWiki Commons
  2. XCOMMONS-3909

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

    XMLWordPrintable

Details

    • Unit
    • Unknown
    • N/A
    • N/A

    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.

      Attachments

        Issue Links

          Activity

            People

              MichaelHamann Michael Hamann
              MichaelHamann Michael Hamann
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: