Giter Club home page Giter Club logo

Comments (3)

dart-github-bot avatar dart-github-bot commented on July 17, 2024

Labels: area-web, type-bug
Summary: The toJS method on string literals is not being constant folded in dart2js, resulting in unnecessary JavaScript code generation. This leads to larger and less efficient code compared to manually inlining the string literal.

from sdk.

rakudrama avatar rakudrama commented on July 17, 2024

Constant-folding of final top-level/static variables is mostly done by CFE.
final foo = 123; is handled somewhat like const foo = 123; because dart2js can see the RHS is a constant in the Kernel IR.
Unfortunately, dart2js does not compile using a full callgraph-bottom-up schedule, so the non-const initializer expression that reduces to a constant it not seen by the users of the variable.

We could do something more limited if this is a popular code pattern./

from sdk.

mkustermann avatar mkustermann commented on July 17, 2024

We could do something more limited if this is a popular code pattern./

The reason I used that pattern in a benchmark is because on dart2wasm this is not a NOP and we'd do the key conversion every single time we do a map lookup. So it makes sense to hoist it there to top-level which then regresses dart2js.

If we recognize this specially in dart2wasm compiler (see #56046) then using the pattern inline in code (rather than top-levels) would not be needed.

Though any 3rd party user may also think it's more efficient to cache in a top level instead of executing every time - and it would be worse performance. So I think maybe it's a good idea to do this optimization regardless.

from sdk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.