Recently, I had the opportunity to share my experience with SolidJS at a tech meetup. Today, I want to take you through my journey of discovering this interesting framework while trying to optimize a React application for resource-constrained devices.
Late last year, I faced a significant challenge in my project. We needed to optimize our React application running on a device with severely limited resources — low CPU, no GPU, and minimal memory. This constraint led me to explore alternatives that could provide better performance while still using web technologies.
When comparing framework performance, benchmarks are often the first port of call. I came across a comprehensive table of framework benchmarks, focusing on runtime duration and memory consumption. I noticed React in the table, but it was far from the top performers and even had some worrying “red” metrics.
I remember thinking, “We can find React here. It’s very far from very performant options, but it’s still here. It’s still with some green color, right? But it has a cell with red color on it. Who likes red-colored benchmarks? I bet nobody, and I don’t either.”
This observation pushed me to explore options at the top of the benchmark list, which is how I stumbled upon SolidJS.
SolidJS caught my attention for several reasons:
What really intrigued me was its core concept: fine-grained reactivity.
As I dug deeper, I learned that SolidJS uses a concept called “signals” to manage state and reactivity. Unlike React’s component-level re-rendering, SolidJS updates only the specific parts of the DOM that depend on changed signals.
Here’s how I understand it works:
This approach allows for much more efficient updates compared to React’s often broader re-rendering strategy.
To illustrate the differences between React and SolidJS, let’s look at a simple example:
*In the example, we intentionally set initial value inside useEffect to highlight the case when that value depends on some asynchronous parts but left with plain string just for the sake of simplicity.
// React version
function Component() {
const [value, setValue] = useState("");
useEffect(() => {
setValue("Initial");
setTimeout(() => setValue("Updated"), 1000);
}, []);
return (
<input
value={value}
onChange={(e) => setValue(e.target.value)}
/>
);
}
// SolidJS version
function Component() {
const [value, setValue] = createSignal("");
setValue("Initial");
setTimeout(() => setValue("Updated"), 1000);
return (
<input
value={value()}
onInput={(e) => setValue(e.target.value)}
/>
);
}
Some key differences to note:
As I explored further, I found several other interesting aspects of SolidJS:
Our application required optimizations that went beyond what web technologies could offer. However, if we had stuck with web technologies, SolidJS would have been our top choice. While my team ultimately decided not to use SolidJS for our specific use case, I still recommend exploring it, especially if you’re a React developer:
However, it’s worth noting that SolidJS has a smaller community than React or Vue, which might impact the availability of third-party libraries and resources.
For me, SolidJS presents an intriguing alternative to React, especially for applications requiring high performance on limited resources. Its fine-grained reactivity system and adherence to web standards make it a framework worth considering for both new projects and potential React migrations.
While I’ve covered the highlights here, there’s much more to explore in SolidJS. If you’re intrigued, I encourage you to dive deeper, try it out, and see if it fits your needs.
Whether you’re looking to optimize an existing application or start a new project with performance in mind, SolidJS could be the solution you’re looking for. As with any technology choice, be sure to evaluate it against your specific needs and constraints.
Happy coding, and may your applications be ever performant!
Check out our newsletter