patrick-steele-idem / marko-vs-react

DEPRECATED - Test app to benchmark and compare Marko and React
90 stars 5 forks source link

React: assigned key during iteration impacts performance #1

Closed patrick-steele-idem closed 9 years ago

patrick-steele-idem commented 9 years ago

The existing (slower) code is doing the following:

<div>
{searchResultsData.items.map(function(item) {
    return <SearchResultsItem key={item.id} itemData={item}/>
})}
</div>

Based on a suggestion on the Hacker News post, I made a change to use the index of the current iteration:

<div>
{searchResultsData.items.map(function(item, i) {
    return <SearchResultsItem key={i} itemData={item}/>
})}
</div>

This significantly improved the performance of rendering the search results on the client. After the change, React and Marko performed on par for the client-side rendering test. As expected, this made no improvement to server-side rendering improvement of React.

The code and numbers need to be updated to reflect this improvement to React.