GithubHelp home page GithubHelp logo

Performance meta-issue about roact HOT 2 OPEN

roblox avatar roblox commented on May 18, 2024
Performance meta-issue

from roact.

Comments (2)

AmaranthineCodices avatar AmaranthineCodices commented on May 18, 2024

We can also document some performance tips that Roact can't do on its own. One thing that I think has an effect but I've not had time to sit down and build a benchmark for is using named keys instead of the default numeric keys:

-- Write this:
{
    Child1 = someElement,
    Child2 = anotherElement
}

-- Not this:
{
    someElement,
    anotherElement
}

React recommends a similar practice when rendering lists: Lists and Keys

In Roact, the reconciler diffs children using their keys:

roact/lib/Reconciler.lua

Lines 411 to 418 in bbb0663

-- Reconcile existing children that were changed or removed
for key, childInstance in pairs(instance._reifiedChildren) do
local childElement = elementChildren and elementChildren[key]
childInstance = Reconciler._reconcileInternal(childInstance, childElement)
instance._reifiedChildren[key] = childInstance
end

If the key is determined by index, something as simple as inserting an element at the start of the list will change the index of every child, causing at least every child to be updated needlessly, or at worst causing every child to be torn down and re-rendered from scratch.

I don't know how much this actually matters in real-world applications, and I doubt it's noticeable outside of very, very large lists, but it's still a good practice.

from roact.

LPGhatguy avatar LPGhatguy commented on May 18, 2024

I'm building a benchmarking tool now due to increased internal pressure to get a better bearing on Roact's performance problems. A bunch of people are blocked on stuff being slow v.v

It's in another branch, I'll have a PR up either today or tomorrow.

from roact.

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.