Skip to content

inlineCommonChunks: PIFE optimization or not #11

Open

Description

@hyfdev

Posed by @overlookmotel before

But... I realised that probably they should not be PIFEs at all, because actually they're not executed in most cases.

// main.js
import("A.js"); // logs 1, expected: 1
import("B.js"); // logs 2, expected: 2
import("C.js"); // logs 3, expected: 3

// A.js
__share("helper.js", (module, exports) => {
  let n = 0;
  exports.inc = function inc() {
    n += 1;
    return n;
  };
});
const { inc } = __share_require("helper.js");
console.log(inc());

// B.js
__share("helper.js", (module, exports) => {
  let n = 0;
  exports.inc = function inc() {
    n += 1;
    return n;
  };
});
const { inc } = __share_require("helper.js");
console.log(inc());

// C.js
__share("helper.js", (module, exports) => {
  let n = 0;
  exports.inc = function inc() {
    n += 1;
    return n;
  };
});
const { inc } = __share_require("helper.js");
console.log(inc());

In the above example, the __share-wrapped function in whatever module loads first is immediately executed. But the functions in the other 2 chunks are not executed immediately, and in fact aren't executed at all.

The whole point of inline chunks is that you don't know which __share will execute first (if you did, it wouldn't need to be shared, and could be static linked).

So forcing every function to be eagerly parsed (PIFE technique) is probably a de-optimization - in most cases, V8's default behavior of skipping parsing these functions is ideal, as mostly they'll never be executed.


I think

So forcing every function to be eagerly parsed (PIFE technique) is probably a de-optimization

makes sense. So probably no PIRF optimization. @sapphi-red cc

Activity

  1. sapphi-red commented on Aug 24, 2026

    @sapphi-red
    Member

    yeah, I think @overlookmotel have got a point. It might be worth paying the cost for subsequent navigations as the first one might be the most important, but probably not worth as a default.

  2. hyfdev commented on Nov 4, 2026

    @hyfdev
    MemberAuthor

    It seems that applying PIFE is positive in the most of cases. See rolldown/rolldown#11282 (comment) for reason.

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

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions