ianprime0509 / zig-xml

XML parser for Zig
http://ianjohnson.dev/zig-xml/
BSD Zero Clause License
17 stars 4 forks source link

perf: apply memory optimizations to `TokenReader` #27

Closed ianprime0509 closed 1 year ago

ianprime0509 commented 1 year ago

These optimizations are analogous to those made in #26 for Scanner. The performance improvement for Reader is less significant, but still noticeable:

Benchmark 1 (48 runs): zig-out/bin-old/reader Gtk-4.0.gir
  measurement          mean ± σ            min … max           outliers         delta
  wall_time           106ms ± 1.72ms     104ms …  110ms          0 ( 0%)        0%
  peak_rss           7.28MB ± 80.9KB    7.08MB … 7.34MB          0 ( 0%)        0%
  cpu_cycles          420M  ± 6.94M      413M  …  438M           0 ( 0%)        0%
  instructions       1.13G  ± 19.3      1.13G  … 1.13G           0 ( 0%)        0%
  cache_references    561K  ± 72.6K      477K  …  878K           2 ( 4%)        0%
  cache_misses       12.7K  ± 1.31K     11.3K  … 18.3K           3 ( 6%)        0%
  branch_misses      1.07M  ± 5.21K     1.07M  … 1.09M           0 ( 0%)        0%
Benchmark 2 (50 runs): zig-out/bin/reader Gtk-4.0.gir
  measurement          mean ± σ            min … max           outliers         delta
  wall_time           101ms ± 1.08ms    98.9ms …  103ms          1 ( 2%)        ⚡-  4.9% ±  0.5%
  peak_rss           7.29MB ± 63.6KB    7.21MB … 7.34MB          0 ( 0%)          +  0.2% ±  0.4%
  cpu_cycles          398M  ± 4.24M      393M  …  410M           1 ( 2%)        ⚡-  5.2% ±  0.5%
  instructions       1.11G  ± 20.8      1.11G  … 1.11G           0 ( 0%)        ⚡-  1.5% ±  0.0%
  cache_references    404K  ±  244K      314K  … 1.82M           4 ( 8%)        ⚡- 28.0% ± 13.0%
  cache_misses       12.0K  ± 1.11K     10.1K  … 15.3K           0 ( 0%)        ⚡-  5.6% ±  3.8%
  branch_misses      1.10M  ± 2.89K     1.10M  … 1.12M           4 ( 8%)        💩+  2.8% ±  0.2%