Uploaded image for project: 'XWiki Platform'
  1. XWiki Platform
  2. XWIKI-25593

The first use of the code macro after a restart is slow because Jython compiles the Python modules of Pygments

    XMLWordPrintable

Details

    • Unknown

    Description

      The first time the code macro highlights code after a restart, it takes 2 to 2.5 seconds, and about 2.7 seconds more the first time it has to guess the language of the code. Each further language takes about 0.3 seconds the first time.

      Most of this time is spent by Jython compiling the Python modules of Pygments to Java classes when importing them, since the Pygments jar contains only their sources (about 215 modules). Jython looks for a precompiled module$py.class next to the source of a module on the class path, so compiling the modules at build time avoids this cost. The remaining time is spent starting Jython (about 1 second, unchanged) and by Pygments itself.

      Measurements

      First use in a JVM, median of 3 runs of a unit test, in milliseconds:

      Step Compiled when imported Compiled at build time
      Starting Jython and creating the parser 948 971
      First highlighting (Java) 1489 592
      First highlighting of another language (Python) 361 214
      First highlighting of another language (XML) 285 131
      First highlighting without a language (guessing loads all the lexers) 2677 1310
      Further highlighting 18 - 47 20 - 42

      The jar of the code macro grows from 45 KB to 2.1 MB with the compiled modules of Pygments (all lexers included, since any language can be used). For comparison, the Pygments jar is 0.96 MB and the Jython jar 15.2 MB. Compiling the modules adds about 5 seconds to the build of the module.

      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: