Skip to content

dart2js: Hoist closures with no free variables #26932

@rakudrama

Description

@rakudrama

In-line closures with no free variables are common, e.g.

aMap.putIfAbsent(aKey, () =>  []));
var names = people.map((person) => person.name).toList();

It is a shame to allocate a closure each time. We should generate code where this is more like a top level or static function, or a lazy initialized top level variable or something custom that avoids any of the reflective overhead of the above two ideas, e.g.

var theClosure;
...
     ...  (theClosure || (theClosure = new FnClosure()))

There is also the possibility of sharing code for different free 'closures' that do the same thing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-web-jsIssues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop.dart2js-optimizationtype-enhancementA request for a change that isn't a bugweb-dart2js

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions