Lattice Grid

blog

Icicle Chart of Request Time by Span

Building…
Loading a live grid…

If you are the performance engineer chasing a slow request, the question is not how long it took. It is which span took the time, and which service it sits in, so you know where to look before you open a profiler.

An icicle chart answers that. The request is a row of nested bars, hung from the top: each service is a band, the parent span sits beneath it and the spans beneath that, and every bar is as wide as the time it spent. The chart above is bound to the grid beneath it, one row per span, so filtering the rows redraws the chart. Filter the Service column to Payments and only the payment spans are left, with the slow one filling the width.

Why an icicle and not a flame graph or a treemap

A treemap hides depth inside nested rectangles, and the eye has to hunt for the parent. An icicle lays every level out in a row, so you read the nesting straight down and compare widths along one edge. That is what a trace needs: the slow span is simply the widest bar on its row.

The chart over a grid

The chart reads the grid’s rows, and the tree it draws is the grid’s own grouping. Group the grid by service, then parent span, then span, and the icicle has a band per service with the parent beneath it and a bar for each span. The measure, y, sets the width, and a parent is as wide as its spans added together. The icicle is its own small module, so import it after the charts module. Here is the example in plain JavaScript, with sample rows inline in place of your own.

import { createGrid } from '@toclocoinc/lattice-grid';
import '@toclocoinc/lattice-grid/css';
import { createChart } from '@toclocoinc/lattice-grid/modules/charts';
import '@toclocoinc/lattice-grid/modules/chart-icicle';

const rows = [
  { id: 1, service: 'Gateway', parent: 'route request', span: 'auth check', ms: 12 },
  { id: 2, service: 'Gateway', parent: 'route request', span: 'routing', ms: 6 },
  { id: 3, service: 'Checkout', parent: 'build order', span: 'price items', ms: 35 },
  { id: 4, service: 'Checkout', parent: 'validate', span: 'stock check', ms: 41 },
  { id: 5, service: 'Payments', parent: 'authorise card', span: 'fraud screen', ms: 88 },
  { id: 6, service: 'Payments', parent: 'authorise card', span: 'bank call', ms: 380 },
  { id: 7, service: 'Database', parent: 'orders', span: 'insert order', ms: 26 },
];
const gridEl = document.createElement('div');
const chartEl = document.createElement('div');
gridEl.style.height = '240px';
chartEl.style.height = '360px';
document.body.append(gridEl, chartEl);

const grid = createGrid(gridEl, {
  rowKey: 'id', rows, groupDefaultExpanded: false,
  columns: [
    { field: 'service', title: 'Service', filter: { type: 'set' }, group: { enabled: true, index: 0 } },
    { field: 'parent', title: 'Parent span', group: { enabled: true, index: 1 } },
    { field: 'span', title: 'Span', group: { enabled: true, index: 2 } },
    { field: 'ms', title: 'Time (ms)', type: 'number', total: 'sum' },
  ],
});
createChart({ grid, container: chartEl, type: 'icicle', y: 'ms',
  title: 'Where one request spends its time' });

The same thing in React

The React adapter is a factory, so you build the component once at module scope. The ref’s grid is the real grid, which is what the chart binds to.

import React, { useEffect, useRef } from 'react';
import { createGrid } from '@toclocoinc/lattice-grid';
import '@toclocoinc/lattice-grid/css';
import { createLatticeGrid } from '@toclocoinc/lattice-grid/modules/react';
import { createChart } from '@toclocoinc/lattice-grid/modules/charts';
import '@toclocoinc/lattice-grid/modules/chart-icicle';

const LatticeGrid = createLatticeGrid({ React, createGrid });
const rows = [
  { id: 1, service: 'Gateway', parent: 'route request', span: 'auth check', ms: 12 },
  { id: 2, service: 'Checkout', parent: 'build order', span: 'price items', ms: 35 },
  { id: 3, service: 'Payments', parent: 'authorise card', span: 'fraud screen', ms: 88 },
  { id: 4, service: 'Payments', parent: 'authorise card', span: 'bank call', ms: 380 },
];
const columns = [
  { field: 'service', title: 'Service', filter: { type: 'set' }, group: { enabled: true, index: 0 } },
  { field: 'parent', title: 'Parent span', group: { enabled: true, index: 1 } },
  { field: 'span', title: 'Span', group: { enabled: true, index: 2 } },
  { field: 'ms', title: 'Time (ms)', type: 'number', total: 'sum' },
];

export function RequestIcicle() {
  const gridRef = useRef(null);
  const chartRef = useRef(null);
  useEffect(() => {
    const chart = createChart({ grid: gridRef.current.grid, container: chartRef.current,
      type: 'icicle', y: 'ms' });
    return () => chart.destroy();
  }, []);
  return (<>
    <LatticeGrid ref={gridRef} rowKey="id" columns={columns} rows={rows}
      groupDefaultExpanded={false} style={{ height: 200 }} />
    <div ref={chartRef} style={{ height: 320 }} />
  </>);
}

The options used

These are the rows of the charts reference for the options in the listings above.

Option Type What it does
grid Grid Required. The grid to read.
container Element or string Required. Where to draw.
type string 'icicle' here, nested bars drawn from the grid’s group tree.
y string The measure column. Here it is the time a span spent, which sets its width.
title string Drawn above the plot.

The tree itself comes from the grid’s grouping, one level per grouped column in order, so x is not used.

Reading the canvas

The wider the bar, the more time the span spent, and the row it sits on is its depth in the request. In the example, the bank call under Payments fills far more of the width than any other span, so it is the one to look at first. A wide parent made of many narrow spans is a different problem: no single call is slow, but the work adds up, and that is a question for the code that makes the calls.

Next

See the icicle beside the other nested charts in the hierarchy charts family demo, read the full list of chart types on the charts page, or follow the how-to for a chart that follows the grid.

Read next

  • Packed Circle Chart of Teams by Headcount

    Bind a packed circle chart to a grid of teams: each circle is sized by headcount and packed inside its department. Filter the rows to redraw it.

  • Voronoi Treemap of Market Share by Brand

    Bind a Voronoi treemap to a grid of brand shares: organic cells sized by share, one region per category. Filter the rows to redraw the chart.

  • Waffle Chart for Survey Answers

    Bind a waffle chart to a grid of survey answers: a hundred squares per question, each one percent of respondents, redrawn when you filter the rows.

All posts RSS