Skip to content

perf(runtime): compiled Activity retains Fragment refs without using them #1789

Closed

Description

@domgan-oai

Compiled Activity-only consumers unnecessarily retain the full FragmentInstance implementation. The dependency comes from queueCurrentActivityRefs, which classifies each visible ref with instanceof FragmentInstance. This imports the constructor and its traversal/listener/focus machinery even when no Fragment refs are used.

Reproduction: production-bundle the following reachability entries against 3754039dcb96e15e25081089d8c51d97f7c11dc9 using esbuild 0.28.1, browser ESM, es2022, tree shaking, minify, NODE_ENV="production" and profiling disabled. Compare gzip at level 9, Node 26.4:

// Activity helpers, without Fragment refs
export { __createVoidRoot, activityBlock } from 'octane';
// Control: a consumer that really does need Fragment refs
export { __createVoidRoot, activityBlock, mountFragmentRef } from 'octane';
Entrypoint Current raw / gzip Local proof raw / gzip
Void root only 74,161 / 24,764 B identical
Compiled Activity 124,652 / 39,836 B 116,436 / 37,600 B
Compiled Activity + Fragment refs 124,821 / 39,895 B 124,815 / 39,887 B
Generic root 199,690 / 64,004 B identical

The compiled Activity case saves 8,216 B raw and 2,236 B gzip (5.6%). These are helper-export reachability builds, not complete app sizes. Existing generic and five measured app variants stay unchanged.

The runtime already maintains activeFragments for every mounted FragmentInstance, adding in the constructor and deleting on destruction. A local proof replaces the constructor check in this cold Activity reconnect path with membership of that existing set. No new registry or ref-manifest fields are needed. The Fragment constructor remains reachable when it is actually used.

Suggested validation:

  • Initially hidden Activity, repeated hide/reveal and different element/Fragment refs while hidden.
  • Retained host identity and ref cleanup on unmount.
  • A Fragment removed on reveal while a sibling and the containing block stay live.
  • Existing Activity hydration and Fragment event/ref tests in development and production.

The local proof passed 40 targeted tests in each compile mode, including those new cases. Deliberately routing every element ref through the Fragment trampoline fails both new mixed-ref/removal cases. Full-repo checks were unavailable locally; the additional bindings benchmark stopped on a missing dependency. No general-root saving is claimed.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions