Skip to content
This repository has been archived by the owner on Dec 13, 2023. It is now read-only.

Performance meta-issue #22

Open
LPGhatguy opened this issue Jan 29, 2018 · 2 comments
Open

Performance meta-issue #22

LPGhatguy opened this issue Jan 29, 2018 · 2 comments

Comments

@LPGhatguy
Copy link
Contributor

Roact's primary goal is not performance; it's always going to end up slower than writing UI in Roblox by hand and that's okay. @AmaranthineCodices broke down rough performance in a blog post here and showed that Roact is within an order of magnitude of manual UI in at least one simple case.

That being said, there are some improvements that can be made!

Some ideas that can be fleshed out:

@AmaranthineCodices
Copy link
Contributor

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.

@LPGhatguy
Copy link
Contributor Author

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants