Popularity is not Efficiency: Solid.js vs React.js
Tags: frontend, solidjs, react, javascript
Published: 2024-01-01 12:15:59

## Introduction
Two well-known JavaScript frameworks and libraries used for creating user interfaces are [React.js](https://react.dev/) and [Solid.js](https://www.solidjs.com/). Solid.js, a lightweight reactive library, prioritizes fine-grained reactivity and efficient rendering through a [reactive programming](https://www.techtarget.com/searchapparchitecture/definition/reactive-programming) model. However, React.js, which was developed by [Facebook](https://www.facebook.com/), is well known for its [declarative architecture](https://en.wikipedia.org/wiki/Declarative_programming) based on components and its handling of the virtual [DOM](https://legacy.reactjs.org/docs/faq-internals.html#:~:text=What%20is%20the%20Virtual%20DOM,a%20library%20such%20as%20ReactDOM) (Document Object Model). Different approaches to [state management](https://www.techtarget.com/searchapparchitecture/definition/state-management) and reactivity set these tools apart, even though they both enable developers to create dynamic and interactive web apps.

> Efficient front-end development is necessary for excellent online performance. Rendering speed, bundle size, and developer experience are all greatly impacted by the choice of your framework, which is important when creating high-performing, user-friendly apps.

## Comparing Features
In terms of the reactive programming idea, Solid and React provide good solutions. But the fine-grained reactivity architecture of Solid.js sets it apart; when there is a change in data, it updates only the necessary components. In scenarios with deeply nested components, this could result in better performance as compared to React's virtual DOM technique.

But with React, developers can build scalable and maintainable apps thanks to its virtual DOM and component-based design.Virtual DOM maximizes rendering efficiency by reducing the need for pointless re-renders.

> React's virtual DOM is a copy of the actual DOM; when changes take place, React updates the portion of the copy that was affected. Next, it updates the real DOM with the portion of the modified virtual DOM that isn't present in the real DOM by comparing it to the previous version. 

## Performance Comparison
Web development relies heavily on rendering speed and optimization strategies, which Solid.js and React.js handle differently. Solid.js provides highly efficient updates with fine-grained reactivity, which is especially useful in complicated settings.

To optimize rendering for large-scale applications, React.js combines a [diffing](https://peeyushjss.medium.com/understanding-the-diffing-algorithm-in-react-js-9e9b71940341) method with a virtual DOM and component-based design. The decision is based on the particulars of the project; Solid.js excels at exact reactivity, whereas React.js uses a virtual DOM method to provide efficiency for larger apps.

### Real-world application benchmarks
[JavaScript benchmarks](https://github.com/krausest/js-framework-benchmark) are instruments for measuring the speed and effectiveness with which a JavaScript engine—such as the ones found in web browsers—can complete particular tasks. Benchmarks are used by developers and browser vendors to evaluate various engines, find places in the code where improvements are needed, and make sure JavaScript standards are being followed.

Though this benchmark compares a number of actions between solid and ReactJs, in this explanation I have thoroughly examined the solid-store, react-hook, and react-redux actions, offering insightful information on the create rows activities.
#### Duration in milliseconds ± 95% confidence interval (Slowdown = Duration / Fastest)
![bench01](https://hackmd.io/_uploads/rkpgnVhvp.png)
The average duration of React hooks is 45.6 milliseconds, and we are fairly confident that the true duration falls within the range of 45.3 to 45.9 milliseconds. Similarly, for React-Redux, the average duration is 49.1 milliseconds, with a confidence interval of 0.7, suggesting that the true duration likely falls between 48.4 and 49.8 milliseconds. The fastest among the three is Solid.js store, with an average duration of 43.5 milliseconds and a confidence interval of 0.4, indicating that its performance is likely between 43.1 and 43.9 milliseconds. Lower values and narrower confidence intervals generally suggest better and more consistent performance.
![bench2](https://hackmd.io/_uploads/SJRf2EnP6.png)
Start-up metrics, represented by Lighthouse scores with mobile simulation, provide insights into the performance of different technologies.
These scores reflect the efficiency and speed of each technology during application startup. The higher the score, the better the performance. In this comparison, React Redux has the highest score of 2626.2, indicating that, among the three, it exhibits the fastest start-up time and overall better performance during the initial loading of the application.

![bench3](https://hackmd.io/_uploads/H1sQ2E2Pp.png)
When we compute a 95% confidence interval using memory allocation data, we are describing a range within which we have a high degree of confidence regarding the actual average memory allocation value. This statistical measure acknowledges the inherent variability in memory allocation measurements and helps to provide some degree of confidence regarding the accuracy of our estimation.

## Developer Experience
React offers a gradual learning curve with widespread adoption and extensive [documentation](https://react.dev/learn), while Solid.js emphasizes simplicity and minimalism. Striking a balance involves considering the team's familiarity with reactive programming and the project's complexity to determine the most suitable framework for adoption.

React's mature ecosystem and widespread [community](https://react.dev/community) support provide robust tooling. Solid.js, though newer, offers a growing [community](https://discord.com/invite/solidjs) and streamlined minimalism. Balancing considerations involve weighing the benefits of React's extensive tooling against Solid.js' focused approach, depending on specific project requirements and preferences.

## Use Cases and Recommendations
There are a few factors to take into account while deciding which of the two frameworks to use. These are my opinions, and whether or not they are accepted by everyone is irrelevant.

### Solid
- Solid.js is well-suited for scenarios where fine-grained reactivity is crucial.
- If developers are already familiar with reactive programming concepts, Solid.js might be a preferred choice.

### React
- React's virtual DOM and component-based architecture are well-suited for building large and complex applications
- In situations where leveraging a mature ecosystem and benefiting from community support are essential, React provides a strong foundation.
 
## Conclusion
Large-scale apps benefit from React's virtual DOM and rich ecosystem, although it may lead to larger bundle sizes. Solid.js is perfect for exact scenarios and lightweight applications because of its superior fine-grained reactivity and minimalism, which lead to smaller bundle sizes and faster rendering. The decision is based on optimization priorities and project specifics.