Skip to content

Improve array speed check, update benchmarks#1042

Merged
barryvdh merged 2 commits intomasterfrom
json-speed-check
Apr 5, 2026
Merged

Improve array speed check, update benchmarks#1042
barryvdh merged 2 commits intomasterfrom
json-speed-check

Conversation

@barryvdh
Copy link
Copy Markdown
Collaborator

@barryvdh barryvdh commented Apr 5, 2026

Benchmark: CliDumper (baseline) vs HtmlDataFormatter vs JsonDataFormatter
Iterations per test: 500
────────────────────────────────────────────────────────────────────────────────────────────────────

1. FORMATTING SPEED
   CLI:  VarCloner + CliDumper (Symfony baseline)
   HTML: HtmlDataFormatter (server-rendered HTML)
   JSON: JsonDataFormatter (client-rendered, plain arrays + dump nodes)
────────────────────────────────────────────────────────────────────────────────────────────────────
Test Case       │          CLI │         HTML   vs CLI │         JSON   vs CLI
────────────────────────────────────────────────────────────────────────────────────────────────────
small_array     │     14.3 µs │     17.6 µs     +23% │       458 ns     -97%
nested_array    │    269.1 µs │    386.4 µs     +44% │      6.7 µs     -98%
object          │     38.1 µs │     58.5 µs     +53% │     16.3 µs     -57%
large_array     │    256.4 µs │    368.2 µs     +44% │      5.4 µs     -98%
deep_nesting    │     21.6 µs │     31.6 µs     +46% │       750 ns     -97%
complex         │    111.8 µs │    161.5 µs     +44% │        3 µs     -97%
idx_depth2      │       36 µs │     53.1 µs     +48% │      1.1 µs     -97%
idx_depth3      │      109 µs │    159.8 µs     +47% │      2.9 µs     -97%
idx_depth4      │      330 µs │    479.9 µs     +45% │      8.4 µs     -97%
idx_depth5      │    983.9 µs │      1.48 ms     +51% │     24.9 µs     -97%
idx_depth6      │      3.03 ms │      4.06 ms     +34% │    144.8 µs     -95%
obj_depth4      │     50.7 µs │     71.6 µs     +41% │       24 µs     -53%
────────────────────────────────────────────────────────────────────────────────────────────────────
TOTAL (mean)    │      5.27 ms │      7.47 ms     +42% │    241.5 µs     -95%

2. TRANSPORT SIZE (json_encode of formatted result)
   All formatters produce output that gets json_encode'd for transport.
────────────────────────────────────────────────────────────────────────────────────────────────────
Test Case       │          CLI │         HTML   vs CLI │         JSON   vs CLI
────────────────────────────────────────────────────────────────────────────────────────────────────
small_array     │         75 B │        446 B    +495% │         34 B     -55%
nested_array    │       2.6 KB │      10.8 KB    +319% │       1.1 KB     -56%
object          │        288 B │       1.7 KB    +491% │        551 B     +91%
large_array     │         3 KB │      11.7 KB    +286% │         2 KB     -33%
deep_nesting    │        208 B │        905 B    +335% │         67 B     -68%
complex         │       1.1 KB │       4.7 KB    +316% │        450 B     -61%
idx_depth2      │        256 B │       1.5 KB    +509% │         70 B     -73%
idx_depth3      │        895 B │       4.7 KB    +441% │        214 B     -76%
idx_depth4      │         3 KB │      14.6 KB    +393% │        646 B     -79%
idx_depth5      │       9.8 KB │      44.7 KB    +354% │       1.9 KB     -81%
idx_depth6      │      32.4 KB │     125.5 KB    +287% │       5.7 KB     -82%
obj_depth4      │        466 B │       2.6 KB    +466% │        821 B     +76%
────────────────────────────────────────────────────────────────────────────────────────────────────
TOTAL           │        54 KB │     223.7 KB    +314% │      13.5 KB     -75%

3. BATCH SIMULATION (typical page: format all test cases + json_encode)
────────────────────────────────────────────────────────────────────────────────────────────────────
Formatter                   Median    vs CLI
────────────────────────────────────────────────────────────────────────────────────────────────────
CLI (baseline)             5.25 ms       —
HTML                       7.46 ms      +42%
JSON                     270.3 µs      -95%

Payload size                          vs CLI
────────────────────────────────────────────────────────────────────────────────────────────────────
CLI (baseline)             54.2 KB       —
HTML                      223.8 KB     +313%
JSON                       13.7 KB      -75%

4. ASSET OVERHEAD
────────────────────────────────────────────────────────────────────────────────────────────────────
CLI:  no assets (text only, no browser rendering)
HTML: inline_css (Sfdump CSS):    5.6 KB  (inline, sent every page)
HTML: inline_js (Sfdump JS):      12 KB  (inline, sent every page)
JSON: vardumper.css:               3.2 KB  (static, cached by browser)
JSON: vardumper.js:                20.2 KB  (static, cached by browser)

────────────────────────────────────────────────────────────────────────────────────────────────────

So conclusion: by average this is 20x faster then the CLI dumper, and >25x faster then the HTML dumper
And the size is 1/4th of the CLI size and 16x as small as HTML.

It does increase the Javascript a bit, but that is minified + cached on each request.

Biggest request is now on the 'happy' flow of just plain arrays, but a lot of config/request stuff is just a plain array, where we now skip processing entirely.

@barryvdh barryvdh merged commit 87a8ff4 into master Apr 5, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant