One of the cool things about React is that it managed to pull a lot of people into the component world. Even though there was initial resistance, the ideas seem to have stuck. Maybe the question is, what next?
Inferno, a blazing fast React-like UI library by Dominic Gannaway might be one of the answers.
I'm currently a Software Development Engineer at Tesco, based in London. I've been developing and writing actual software since I was 15 years old, but I was first interested in coding when I was around 7 years old. (It was Visual Basic 5 back then!)
I'm a huge fan and advocate of web technologies, and I've always enjoyed optimising and making things fast. These days I spend a lot of time building complex UIs, middlewares, tooling and all the other things you would associate with a full-stack JavaScript engineer.
In my free time, I enjoy being a Dad (I've got two kids) and spending time with my family. I also enjoying working on open-source projects and I love to attend meetups and conferences when I get the chance.
Inferno is a JavaScript library that helps developers build user interfaces for websites and apps. Inferno intentionally builds on the same API as React, so developers do not have to invest time/money in learning a completely new way of building things.
In many ways I think React has been a game-changer for the web UI community. It scrapped the old ways of doing things like we'd been doing them for years on the server (MVC for example) and offered an approach that inspired many different patterns and design discussions; e.g., one-way data flow, components over templates, JSX, Virtual DOM.
Inferno was designed to be really, really fast and lightweight while offering a bunch of out-of-the-box features that makes working with a React-like project a bit nicer.
There's also a big push right now to improve the experience on mobile and it's good to see so many people taking notice – as, in my opinion, mobile performance has been really poor for a long time. Inferno started off nearly 2 years ago as my attempt to fix the problems with mobile performance.
Like many other libraries and frameworks, Inferno uses a Virtual DOM. Virtual DOM is a tiny abstraction above the real DOM that provides Inferno with a list of instructions on what the UI will look like; so that when a user creates components or virtual DOM nodes (VNodes
), they are describing how they'd like their UI to look.
Inferno takes all this information and works out the least amount of changes necessary to update the webpage from one state to the next. It makes this process fast by leveraging several optimisations that modern JavaScript engines provide; along with the mounds of trial-and-error it required to improve "touching" the DOM.
This might get a bit technical, but I've been asked about it plenty of times so I thought it would be best to share my experiences:
VNode
objects, Inferno reuses previous properties (even if the property name doesn't really align anymore with what's being put within it). Furthermore, DOM nodes are also stored and recycled, reducing the cost of having to recreate large DOM trees and computing all the internal visual calculations again.firstChild
, lastChild
, parentNode
, nextSibling
, createElement
, removeChild
, insertBefore
, replaceChild
). Inferno avoids using childNodes
and innerHTML
as these methods tend to be very expensive. A nice optimisation trick to clear a DOM's content was to use textContent('')
.foo === null
, doing isNull(foo)
. We found that this really helped improve bundle size, and in some cases it also improved JIT performance (when the inline budget for inlining hadn't been fully consumed).There are plenty more optimisations going on under the hood, so I'd recommend reading the sourcecode if anyone is interested in learning more.
Inferno doesn't try to be too different from React. Very much like Preact, Inferno enjoys having lots of similarities with React. Inferno supports many different ways of creating UIs, such as: JSX (Inferno has its own Babel plugin for this), HyperScript and good ol' createElement()
from React.
Inferno differs in that it offers some additional features that React or Preact don't have (at the expense of some file size):
shouldComponentUpdate
and componentDidMount
on functional components.createClass
isn't in Inferno's core; it's a separate package called inferno-create-class
. The same applies for ES2015 class components. This helps reduce filesize for people who simply don't need to carry things that they will never use.linkEvent
helper for passing state
/props
/this
to an event callback without needing to use arrow functions or bind()
. Not only is it a lot faster than the alternatives, but you can use it on functional components too:import Inferno, { linkEvent } from 'inferno';
function handleClick(props, event) {
props.validateValue(event.target.value);
}
function MyComponent(props) {
return (
<div>
<input type="text" onClick={linkEvent(props, handleClick)} />
<div>
);
}
I developed Inferno because (1) curiosity/research and (2) I ran into too many performance issues too often while trying to build a highly complex mobile web app.
Two years ago, when this project started, I was really frustrated with the mentality that a lot of the community had in regards to mobile performance. I was commonly told that "mobile is fast enough" or "people simply don't need aything faster" or "X is already as fast as it gets".
Thankfully, that mentality has changed since then and now people are starting to become more aware of the real problem users are having; especially in emerging countries with poor web experiences on mobile.
The focus for me and the rest of the Inferno team is to get 1.0 released before Christmas (along with the website). I have some big plans for 2017, but it's a bit too early to announce them right now. :)
I think there is going to be a big shift towards making things smaller and faster. I think we've only just begun tapping into the potential of JavaScript compiling. With the work that Rich Harris has done with Svelte, along with the work by the Ember and Angular guys on AoT (ahead of time) compiling, we'll see WebAssembly compilation start to take off too. I think 2017 will be an interesting year for the future of web development.
Get into open source, either on an existing project or start your own. You'll learn huge amounts from the experience and get to tap into a huge community of very smart people.
Jason Miller and Ryan Tsao. They're both doing fantastic work!
I'd like to say a big thank you to the team behind making Inferno awesome. Sampo Kivistö, Ryan M, Luke Sheard, Boris Kaul, Luke Edwards and many others! They've been great.
Thanks for the interview Dominic! If there's one thing that sets Inferno apart from my point of view, it's how it expands function based components through a beautifully designed hook system. That solves a major pain point for me even if it's not standard React code.
You should check out the official site and Inferno on GitHub to learn more about the project and those hooks. Maybe 2017 is the big year for Inferno.