Using the Jennifer profiler

Jennifer

jennifer profile in depth: every flag, every column, and one program taken from slow to fast.

November 2026, by @mplx.
Based on Jennifer 0.26.0

Powered by Jennifer's Cantrip - Markdown into slide decks, https://github.com/jennifer-language/cantrip
1 / 19

What it measures

$ jennifer profile prog.j               # profile on stdout
$ jennifer profile prog.j > prof.txt    # output still on screen
$ jennifer profile prog.j in.csv 10     # arguments after the file
2 / 19

Every flag

FlagEffect
(none)statement profile: hits and wall-clock time per position
--allocsvalue copies instead of time
--format=tablethe human-readable text (default)
--format=pprofgzipped protobuf for go tool pprof or speedscope
--format=traceChrome-trace JSON of the call timeline
--sysmoddir D, -I DIR, --vendor DIRmodule paths, as for run

--allocs --format=trace is refused: copies have no timeline.

3 / 19

A first profile: counting primes

use io;

func isPrime(n as int) {
    if ($n < 2) { return false; }
    def d as int init 2;
    while ($d * $d <= $n) {
        if ($n % $d == 0) { return false; }
        $d = $d + 1;
    }
    return true;
}

The top level then counts primes below 20,000 with isPrime (lines 13-17).

4 / 19

The statement table

    HITS          SELF           CUM  POSITION
       1    6.383522ms  232.412626ms  table.j:14:1
   20000   23.886848ms  226.029104ms  table.j:15:5
   19998  139.414917ms  195.766084ms  table.j:6:5
  301275   35.914906ms   37.527785ms  table.j:7:9
  283539   18.823382ms   18.823382ms  table.j:8:9
   ...
13 positions, 687075 statement executions, 232.446026ms total
self time (top-of-tree cum 232.412626ms)

HITS: runs. SELF: time in the statement alone. CUM: plus all it called.

5 / 19

Reading the rows

6 / 19

Recursion and call depth

$ jennifer profile fib.j            # fib(20), doubly recursive
   HITS         SELF          CUM  POSITION
      1     33.002us  22.098234ms  fib.j:8:1
  10945  15.693501ms  22.064122ms  fib.j:5:5
  21891     5.0873ms   6.371731ms  fib.j:4:5

Max call depth (deepest chain of nested function calls): 58
  DEPTH  CALL SITE
     58  fib.j:5:12
7 / 19

When recursion goes too deep

$ jennifer profile deep.j
deep.j: runtime error at deep.j:5:16: call stack too deep:
  exceeded the depth limit of 10000 nested calls, blocks,
  and expressions (possible infinite recursion)
  HITS         SELF          CUM  POSITION
  3334   28.87603ms  42.916067ms  deep.j:5:5
Max call depth (deepest chain of nested function calls): 10000
  DEPTH  CALL SITE
  10000  deep.j:5:16
8 / 19

Profiling a module through its tests

$ jennifer test --profile modules/bloom_test.j 2>&1 >/dev/null
  HITS        SELF          CUM  POSITION
     6   358.963us  20.274782ms  bloom.j:123:5
   517  1.587072ms  19.915819ms  bloom.j:124:9
     1       4.2us  19.739637ms  bloom_test.j:85:5
9 / 19

Spawned tasks are profiled too

func work(seed as int) {
    def acc as int init $seed;
    for (def i in 0..200000) {
        $acc = ($acc * 31 + $i) % 1000003;
    }
    return $acc;
}
for (def n in 1..5) { $jobs[] = spawn { return work($n); }; }
def results as list of int init task.waitAll($jobs);
10 / 19

Self time adds up across tasks

    HITS          SELF           CUM  POSITION
       4      106.21us  1.130455315s  par.j:13:41
       4  1.014569177s  1.130310073s  par.j:6:5
       1  289.751393ms  289.751393ms  par.j:14:1
  800000  115.740896ms  115.740896ms  par.j:7:9
10 positions, 800024 statement executions, 1.420305399s total
self time (top-of-tree cum 1.130455315s)

The whole profiled run took 296 ms of wall-clock time.

11 / 19

--allocs: three kinds of copy

SectionWhat it countsColumns
Eager copiesa def, assignment or parameter that deep-copied a list, map, struct or bytesCOUNT, BYTES, TYPE
Spawn-frame copiesthe scope snapshot at each spawnCOUNT, TOTAL time
Module-boundary rebuildsa value holding a module's structs, rebuilt to cross a callplus DIR in / out

Sorted by bytes. Strings are shared, so they count nothing.

12 / 19

--format=pprof and --format=trace

$ jennifer profile --format=pprof v1.j > v1.pb.gz
$ go tool pprof -sample_index=self -top v1.pb.gz
      flat  flat%   sum%        cum   cum%
  452.37ms 34.60% 34.60%   452.37ms 34.60%  v1.j:6:5
  201.32ms 15.40% 50.00%   201.32ms 15.40%  bloom.j:100:9
$ jennifer profile --allocs --format=pprof v1.j > a.pb.gz
$ go tool pprof -sample_index=alloc_space -top a.pb.gz
$ jennifer profile --format=trace fib.j > fib.json
13 / 19

Worked case: a Bloom filter, version 1

use io;
import "bloom.j" as bloom;

def f as bloom.Filter init bloom.new(1048576, 4);
for (def i in 0..20000) {
    $f = bloom.add($f, "user{$i}");
}
io.printf("{bloom.mightContain($f, "user7")}\n");

jennifer run v1.j: 1204 ms (best of seven runs).

14 / 19

Step 1: where does the time go?

$ jennifer profile v1.j
   HITS          SELF           CUM  POSITION
      1   18.965016ms  1.742157233s  v1.j:5:1
  20000  719.871952ms  1.723192217s  v1.j:6:5
  20000  115.257686ms  999.523545ms  bloom.j:112:5
  20000  143.919199ms  504.248487ms  bloom.j:97:5
  80000  241.485161ms  241.485161ms  bloom.j:100:9

Line 6 has 720 ms of SELF, but it only calls bloom.add.

15 / 19

Step 2: what is being copied?

$ jennifer profile --allocs v1.j
Eager copies - ...:
  COUNT     BYTES   TYPE    POSITION
  20000   2.5 GiB   Filter  bloom.j:111:17
Module-boundary rebuilds - ...:
  COUNT     BYTES  DIR  TYPE          POSITION
  20000  15.6 MiB  in   bloom.Filter  v1.j:6:10
  20000  15.6 MiB  out  bloom.Filter  v1.j:6:10

Every call copied the whole 128 KiB filter.

16 / 19

Step 3: make it a local

func build(n as int) {
    def f as bloom.Filter init bloom.new(1048576, 4);
    for (def i in 0..$n) {
        $f = bloom.add($f, "user{$i}");
    }
    return $f;
}
def seen as bloom.Filter init build(20000);

400 ms. --allocs: the Filter copies are gone; 40,000 rebuilds stay.

17 / 19

Step 4: one call instead of 20,000

def names as list of string init [];
for (def i in 0..20000) {
    $names[] = "user{$i}";
}
def f as bloom.Filter init bloom.addAll(bloom.new(1048576, 4), $names);
VersionTimeFilter copied
v1, top level1204 ms2.5 GiB
v2, local400 msnone
v3, addAll329 msnone, one call
18 / 19

Read more

Based on Jennifer 0.26.0, November 2026.

19 / 19