Skip to content

Derived-always specialization of an over-budget instance method duplicates the dictionary read per site #326

Description

@Unisay

Problem

Directive derivation (#241) marks a saturated specialization always-inline, and the whole-binding paste copies its unresolved right-hand side into every use site — e.g. the float purs's CSE emits for a repeated dictionary application, bind = Control.Bind.bind bindStateT (verbatim shape from Golden.CprState.Test's corefn). The intended cascade is: the accessor resolves, the concrete instance method pastes, and the constructor folds collapse the chain at each site. When the concrete method exceeds inlineSizeBudget and the instance dictionary carries no .method always field directive, resolveDictionaryProp declines the last step and every site is left holding dict.method(...) — one dictionary field read per site, where the pre-derivation shared binding (local bind = bindStateT.bind, a single read at module init) was strictly better on both code size and speed (Lua 5.1 locals beat hash lookups per call). The derivation currently cannot see this coming: at derivation time the method's settled size is not yet known.

Approach

Candidates, in leaning order: (a) a sharing-repair pass after the specialize fixpoints that re-binds a dictionary field read surviving at two or more sites to a shared top-level binding — the dictionary analogue of shareForeignAccessors (#248), repairing the shape regardless of which pass duplicated it; (b) budget-aware derivation that declines always-inline when the specialization's settled form would not resolve at sites — requires anticipating the specialize fixpoint's dictionary resolution at derivation time, a fragile layer crossing; (c) letting a derivation-originated paste bypass the field-resolution budget — changes the calibrated growth semantics and needs measurement before committing. Lean (a).

Prerequisites / Relations

Builds on #241. Pairs with the #242 default directive pack: the pack is what will put arity=N on class accessors at scale, so pack tuning should assume this stall exists until fixed. A regression case needs no pack — a golden with a directive-annotated accessor and an over-budget instance method reproduces it.

Verification / Measurement

A golden with a class accessor under arity=1 and an instance method over the size budget shows the sites sharing one field read rather than one read per site, with eval output unchanged. Size/speed effect on the corpus measured through the bench harness (#172) once the pack lands directives in the package set.

Metadata

Metadata

Assignees

No one assigned

    Labels

    OptimisationA Compiler Optimisationarea: irIR / optimizer / DCE / inlinerenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions