New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Styled Components injects forwardRef in every component generating unecessary overhead #3739
Comments
the issue you linked is over 2 years old - is it still relevant? |
I'll run some profilings later today and post the results here |
@jantimon After doing some deeper digging I believe this is still relevant.. React's forwardRef uses Speed of Object.defineProperty vs a straight setter can be seen on this example here. |
the code you mentioned is only active during development - or did I miss something? did you do any benchmarks how much slower rendering 1000 forward ref vs 1000 normal components? would be quite interesting to understand the real impact :) did you see this one here?
|
Using a sample of 10k children Those results are interesting, though not for the reason I imagined styled-components seems to add significant overhead time to render time to components. Nonetheless forwardRef does not have the impact as I thought, as you mentioned it did have the Devtools profiles: profiles.zip Code used: import React, { forwardRef, ReactNode } from 'react';
import logo from './logo.svg';
import './App.css';
import styled from 'styled-components';
const array = new Array(10000).fill(0);
function Div({children}: {children: ReactNode} ) {
return <div>{children}</div>
}
const FowardRef = forwardRef((props: {children: ReactNode}, ref) => <div>{props.children}</div>);
const Styled = styled.div``;
function App() {
return (
<div className="App">
<header className="App-header">
{array.map((_,index) => <Styled>Test line {index}</Styled>)}
</header>
</div>
);
}
export default App; |
Styled component injects forwardRef into every component, forwardRef adds an overhead and has considerably more impact on a Component's render time and JS thread time compared to a regular component, causing FPS drops, tha has been widely discussed here.
I'm wondering if the styled-components' team is aware of that and if it'd be of your interest if I were to open a PR proposing removing forwardRef from the default implementation, making it optional.
The text was updated successfully, but these errors were encountered: