Skip to content

fix: cut createRenderer() from ~400 µs to ~60 ns when cache is set via configure() - #176

Open
RomainLanz wants to merge 1 commit into
edge-js:6.xfrom
RomainLanz:fix/supercharged-cache-configure
Open

RomainLanz wants to merge 1 commit into
edge-js:6.xfrom
RomainLanz:fix/supercharged-cache-configure

Conversation

@RomainLanz

Copy link
Copy Markdown
Member

Hi ! 👋

AdonisJS calls Edge.create() and then edge.configure({ cache: app.inProduction }). The superCharged plugin took its recurring flag from the constructor options only, so configure() did not change it. In production, each createRenderer() call then ran existsSync and a recursive readdirSync on the components directory of each mounted disk. AdonisJS creates one renderer per request (the ctx.view getter, which session, shield and auth touch on every request, JSON responses included).

Now configure() stores the cache flag, and #executePlugins reads it to decide if the bundled plugins run again. With cache disabled, the components list still refreshes on each render.

createRenderer() with create() + configure({ cache: true }), median of 3 runs, Node 26.10, no profiler attached:

Components Before After
0 7.0 µs 59 ns
20 90.7 µs 58 ns
100 403.6 µs 58 ns
Control, create({ cache: true }) 60 ns 59 ns

In an AdonisJS Inertia React app with 26 components, CPU time per request went from about 1,140 µs to about 780 µs.

Tests:

  • do not refresh list when cache mode is enabled via configure renders a template that is not compiled yet, so the template cache cannot hide a refresh. The existing cache: true test renders the same template twice, so it passes with or without this fix.
  • refresh list when cache mode is disabled via configure covers create({ cache: true }) followed by configure({ cache: false }).

Not covered: user plugins registered with use() keep their own recurring option. This PR does not change them.

The superCharged plugin read its "recurring" flag from the options
given to the constructor. configure() did not update it. AdonisJS calls
Edge.create() and then edge.configure({ cache: app.inProduction }), so
in production the plugin stayed recurring. Each createRenderer() then
did an existsSync and a recursive readdirSync of the components
directory of every mounted disk. AdonisJS creates one renderer per
request.

configure() now stores the cache flag, and #executePlugins reads it to
decide if the bundled plugins run again. With cache disabled, the
components list still refreshes on each render.

createRenderer() after create() + configure({ cache: true }) with 100
components goes from about 400 µs to about 58 ns.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant