Over a million developers have joined DZone.

Benchmarking Vue

DZone's Guide to

Benchmarking Vue

Vue has quickly become one of the more popular ways to work with JavaScript code. In this post, an ardent JS dev outlines his first encounter with Vue.

· Web Dev Zone ·
Free Resource

Deploying code to production can be filled with uncertainty. Reduce the risks, and deploy earlier and more often. Download this free guide to learn more. Brought to you in partnership with Rollbar.

This article builds on my previous articles about Building an interactive DOM benchmark and Adding Preact to a React project

I understand why people like Vue and those people are wrong.

But this isn't a rant about Vue. If you like the ease of porting your 2012-era code to a modern framework, Vue is for you. If you're into Mustache templates, Angular directives, and love to split your code into templates, scripts, and styles just like ye olden times, Vue is perfect. Hell, if you love nothing more than to use cumbersome workarounds to avoid JavaScript classes => Vue.

You do you. I built a Vue component and hated every minute of it. But it's important to try new things.

It took about 2 hours to add Vue to my interactive DOM benchmark. Half the time I spent bitching about the Angular 1 style templates. The other half, I complained about 2012-era hacks designed to fake classes.

Oh, and it took an hour just to get it compiling.

Getting started with Vue is easy they said, you'll have fun they said.

vue-loader installs vue-template-es2015-compiler then complains it can't find vue-template-compiler pic.twitter.com/m0w4nmp5Tf

- Swizec (@Swizec) March 4, 2018

A wonderful experience all over...

BUT! I created my first non-trivial Vue component, a simple benchmark!

My First Vue Component

Image title

The Vue benchmark component

You can see the code on GitHub. There are 5 buttons and a scratchpad area that renders a list of immutable nodes. Much like a chatroom or a newsfeed.

Buttons can prepend, insert, append, drop, and remove nodes. Clicks map to methods on the Vue component that manipulate a nodes array in the data. The template renders it as a bunch of divs.

<div class="row benchmark-scratchpad">
    <div v-for="k in nodes">
        {{ k }}

That v-for="k in nodes" syntax is one of my least favorite parts of Vue. Brings back memories of some Angular 1 projects I worked on. Nightmares lasted months.

Click events call instance methods via v-on:click="func". They manipulate the nodes array and that triggers a re-render. These methods look a lot like to their React counterparts, but cleaner because there's no setState in Vue. I liked that.

prepend() {
    this.nodes = [...this.newNodes(), ...this.nodes];

append() {
    this.nodes = [...this.nodes, ...this.newNodes()];

I think that looks more readable and makes more sense than going through setState in React.

However, you have to define instance attributes in a data: key, and instance methods in a methods: key. But you override Vue's internal instance methods in the normal namespace. 

module.exports = {
    // adding attributes here does nothing

    data: function () {
        // this is where you define state
        return {
            nodes: [],
            start: null,
            times: [],
            // ...

    // override Vue instance methods here

    methods: {
        // define custom instance methods here


That's kind of how we used to write code in the old days before JavaScript got better. Did I fall into a time machine?

I've heard you can install plugins and tweak configs to get a better approach going, but if it's not the default in the official docs, it doesn't exist. Ask anyone.

Some people like this, so here we are. It was a fun experiment, I don't like it at all.

Oh, by the way, we render benchmark results using Vue refs and direct DOM manipulation so as to avoid re-rendering via Vue after each render. That would be unfair.

Adding Vue to an nwb-cli Based Project

Getting Vue to compile at all was fun, too. I started the project using nwb-cli, which is not The Official Way™. You're supposed to use vue-cli, but I didn't want to start a new project.

Some finagling with vue-loader was necessary. Two steps:

  1. Install some stuff.
  2. Tweak nwb.config.js.

Install Some Stuff

yarn add vue vue-loader vue-template-compiler 

You need both vue-loader and vue-template-compiler because vue-loader actually installs vue-template-es2015-compiler then complains that it can't find vue-template-compiler. This is confusing.

I installed vuera as well. It gives you a wrapper component so you can render Vue inside your React project. Vue is kept internally autonomous so it shouldn't affect the benchmark, but it makes it easier to put all benchmarks in the same project.

// VueBenchmarkWrapper.js

import React from "react";
import { VueWrapper } from "vuera";
import VueBenchmark from "./VueBenchmark.vue";

export default () => <VueWrapper component={VueBenchmark} />;

Tweak nwb.config.js

After installing Vue, you have to tell Webpack how to use it. That goes in nwb.config.js.

// nwb.config.js
module.exports = {
    type: "react-app",
    webpack: {
        extra: {
            module: {
                rules: [{ 
                    test: /\.vue$/, 
                    loader: "vue-loader" 

You add a rule that tells Webpack to use vue-loader for files ending with .vue. Same as a normal Webpack config file, just wrapped in extra: so nwb knows what to do.

This is where nwb shines over create-react-app. Extra config without eject.

Next Step for the DOM Benchmark

What I want to do next is going to blow your mind. Maybe.

Remember my blockchain-redux experiment from December? I want to use it to make this DOM benchmark collaborative.

Every time you click a button, it adds to the benchmark blockchain, distributes it to everyone, updates graphs on everyone's page. We're going to see how these benchmarks behave in the real world on real people's computers.

That's gonna be fun!

Deploying code to production can be filled with uncertainty. Reduce the risks, and deploy earlier and more often. Download this free guide to learn more. Brought to you in partnership with Rollbar.

web dev ,vue.js ,dom manipulation ,web application development

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}