Skip to content
  • Philip Chimento's avatar
    esm: Improve startup time by delaying imports of native and GI modules · e9dfa02f
    Philip Chimento authored
    By avoiding using import.meta.importSync() and imports.gi at the top level
    of modules that we import during the bootstrap process, we speed up the
    execution of a blank file by 15%, because we don't need to go into any of
    the GI typelib machinery.
    
    Now, the only modules imported at startup are _print, _encoding, _timers,
    and console, in order to provide public global APIs.
    
    I measured the 15% speedup with `perf stat -r 10 -B`. I also used Meson's
    measurements of the test suite to see a noticeable effect: for example,
    running the CommandLine test (which starts many instances of GJS) goes
    goes from 5.4 to 4.9 seconds.
    
    The cost of importing these modules is instead paid at the first time
    they're used. This assumes that it's nearly zero cost to import the
    modules a second time, because they're cached.
    
    In addition, this should make debugging easier because you don't get a big
    log spew of importing GLib if your script doesn't import GLib.
    e9dfa02f