Skip to content

Bad smell: No unified abstraction for optimizaing chunks #3

Open

Description

@hyfdev

Inside of Rolldown, there're multiple passes touch chunks. Like removing unnecessary ones or do some optimizations. They're all built on top of a bare raw Chunk struct.

Bad: Every pass tries to define its own lanague to do similar stuffs.

Owners:

  • feature avoidRedundantChunkLoads
    • predicted_static_import_targets tries to predict something
  • feature mergeCommonChunks
    • would_create_circular_dependency can_merge_without_changing_entry_signature try to predict something
  • feature onDemandWrapping
    • predicted_static_import_edges tries to predict something
    • lowered_static_import_edges alters the chunk graph

At least 3 passes transform/modify the chunk graph, using their own language.

Bad: Every pass interacts with business logic directly rather than abstracts it into domain properties

The point is separating a feature's business logic from the nature it represents.

preserveEntrySignatures: 'strict' means the entry should keep its export signature. Its nature for chunk optimization is a domain property: this chunk's export surface is frozen, no pass may add exports to it.

Marking the feature on the chunk is not enough. We already do that (chunk.preserve_entry_signature), and the pass is still messy: it still has to know what each feature implies.

!chunk.is_async_entry()
  && !matches!(chunk.preserve_entry_signature, Some(PreserveEntrySignatures::Strict))

These two checks are the same domain property spelled as two feature checks: "this chunk's export surface is frozen". A third feature that also freezes the export surface would add a third &&.

Chunks should carry a domain property like export_surface: Frozen | Extendable. Lowering translates every feature onto that one property — preserveEntrySignatures, async entry, whatever comes next.

The optimizer reads the property and never knows the feature exists. The test of a good domain property: multiple features converge onto one.

The worst case today is is_strict_execution_order_enabled(), which forks a whole pass into two graphs inline.

Activity

  1. hyfdev commented on Aug 17, 2026

    @hyfdev
    MemberAuthor

    Another example is about the side effect nature of modules. There're various concepts to distinguish:

    • A module's original source has side effects
    • A module's render output has side effects
    • A module that gets wrapped whose output side effects get delayed to runtime execution

    Modules don't have side effects has similar nature to wrapped modules. They both could be moved around during optimization without worrying about execution order effect. Things like these ideally should be unified into one "representation" so the optimizer doesn't need to care about domain fact either "if the module has side effects" or "if the module is wrapped", instead we just say "the module is free to moved around"

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

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions