Git Product home page Git Product logo

Comments (6)

theKashey avatar theKashey commented on August 16, 2024 2

an extra operation to check what shall be compared might take more time than the actual compare.

from rfcs.

theKashey avatar theKashey commented on August 16, 2024

Sound like https://babeljs.io/docs/en/next/babel-plugin-transform-react-constant-elements.html
Please check facebook/react#3226

from rfcs.

coppyC avatar coppyC commented on August 16, 2024

It's different.

what I say is accelerate react diff.

function Hello(props) {
  <div className="xx" style={{height: 8}}>
    {props.children}
  </div>
}

As I know, in this example, when update the component, react in order to do the diff algorithm, will compare the className, style and children

but the className and style don't use any variables, they don't need to diff.

And react can't judge "Are className is constant value?", then react will compare className

so I think can Babel tell react, what need to compare.

from rfcs.

coppyC avatar coppyC commented on August 16, 2024

I can't understand why it is an extra operation.
I think it's an other operation to replace. like this.

// (exclude Spread Operator like `<div {...props}></div>`)

Object.keys(props).forEach(key => {
  // compare
})

// `dynamicProps` is an string array that babel generate
dynamicProps.forEach(keys => {
  // compare
})

I think dynamicProps.length <= Object.keys(props).length

Actually, many components are constant, they event don't need to compare.

from rfcs.

NE-SmallTown avatar NE-SmallTown commented on August 16, 2024

As I know, in this example, when update the component, react in order to do the diff algorithm, will compare the className, style and children

No, React will just use === to compare the props object, not iterate it

But back to your concerned topic, from my personal perspective, the static/runtime compiler optimization will not be the key goal of React. It has tried prepack and find that is not the way to go, It will provide/figure out a different way to do the 'optimization' based on the UI(research) and (runtime)Js and UX/DX just like they did before(JIT, heuristic, mount/update hooks, JND, GC, something for V8, ...)

from rfcs.

coppyC avatar coppyC commented on August 16, 2024

ok, I understand . Thanks.

from rfcs.

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.