Files
profanity/tests/bench/baseline.csv
jabber.developer2 b1d820462a feat(bench): synthetic load harness for flat-file backend (P1-P5)
End-to-end performance and correctness harness for the flat-file +
SQLite database backends. Lives in tests/bench/, built only on
demand (`make bench`); not part of `make check`.

Components

  gen_history (P1)
    Deterministic corpus generator. Knobs: lines, contacts, years,
    seed, stanza-id mode (uuid/libpurple/conversations/mixed), LMC
    rate, MAM-OOO rate, resources/contact, length profile
    (short/mixed/long/extreme). Emits the canonical
    flatlog/<account>/<contact>/history.log layout used by
    ff_verify_integrity. ~340 LOC.

  bench_runner (P1, P2.5)
    S1 cold tail-access via sparse index
    S2 warm tail-access (page cache hot)
    S3 deep pagination (1000 binary-search lookups)
    S4 first-time index build (cold file -> ff_state_ensure_fresh)
    S5 incremental extend (asserts no full rebuild path)
    S6 real ff_verify_integrity over the contact tree
    Reports total/err/warn/info issue counts in the CSV note.

  bench_long_messages (P2)
    L1-L14 long-message stress: 1KB up to 9.9MB bodies, plus
    oversized line rejection (10MB+1 -> ff_readline returns ""),
    embedded-newline / pipe / emoji body patterns, full parse on
    100x1MB, 1000x100KB sustained append.

  bench_failure_modes (P3)
    F1-F15 failure-injection: truncated last line, mid-file CRLF,
    mid-file BOM, LMC cycle, LMC depth>FF_MAX_LMC_DEPTH, manual
    ': ' in resource, RTL/ZWSP, Latin-1 byte, empty body,
    mtime/inode flip, empty file. Each test asserts expected issue
    levels and reports PASS/FAIL.

  bench_export_import (P5)
    Links real database_export.c + database_sqlite.c + database.c
    and drives log_database_export_to_flatfile /
    log_database_import_from_flatfile under load.
    Subcommands: seed, export, import, roundtrip, verify.
    S7a/b export, S8a/b import, S8e roundtrip with full byte-by-byte
    content diff of every row in (from_jid, to_jid, message,
    timestamp, type, stanza_id, archive_id, encryption, replace_id).

Make targets

  bench-quick / bench / bench-full
  bench-longmsg, bench-failure
  bench-multicontact, bench-lmc, bench-ooo
  bench-export, bench-import, bench-roundtrip
  bench-pipeline, bench-pipeline-max (1M rows)
  bench-compare, bench-update-baseline

Volume controls: BENCH_VOLUME (small/medium/max), BENCH_PIPE_ROWS,
BENCH_PIPE_ROWS_MAX, BENCH_DATA_DIR, BENCH_CSV.

Baseline + regression checking (P4)

  tests/bench/baseline.csv       51 rows: S1-S6 x {small,lmc,ooo}
                                 + L1-L14 + F1-F15 (11 of 15) +
                                 S7/S8 x {pipe100k, pipe1M}.
  compare_baseline.py            median over duplicate rows;
                                 exits 1 on any (scenario, volume)
                                 slowdown >= threshold (default 25%).

Verified at scale

  bench-pipeline-max: 1,000,000 rows, full content diff
    seed   17 s, export 304 s, import 31 s, idempotent re-import 10 s,
    diff 2.7 s -- mismatches=0.

Findings surfaced by the harness

  Export scales super-linearly: 4 s @ 100k -> 304 s @ 1M (76x for
    10x rows). Cause: g_slist_sort on the merged list + per-row
    ProfMessage/ff_parsed_line_t allocations. RSS peaks at 1.4 GB
    on 1M. Worth a follow-up.
  Export progress reporting only fires during the write phase --
    the merge+sort phase (~95% of wall time at 1M) is silent.
  /history export and /history import are blocking on the main
    UI thread; profanity is frozen for the duration (~5 min @ 1M).
  ff_readline sets *truncated=TRUE on partial-write tail but
    ff_verify_integrity does not surface this -- partial writes
    go unflagged (failure-injection F1).
  Parser silently truncates body at first unescaped ': ' if a
    resource was manually edited to contain it (F9).
  In gen_history (caught by the bench's own real-verify pass):
    g_strndup mid-codepoint truncation on UTF-8 bank strings -- fixed.

Linkage strategy

  database_flatfile.c + parser + verify + common.c are linked
  unconditionally. The export/import bench additionally links
  database.c + database_sqlite.c + database_export.c. bench_stubs.c
  provides minimal stubs for log_*, prefs_*, connection_get_jid,
  jid_create, files_*, message_*, ui hooks. integrity_issue_free
  is a weak symbol so it falls back to the real database.c
  implementation when that file is linked.
2026-04-30 15:39:30 +03:00

5.0 KiB

1scenariovolumebyteslineswall_mspeak_rss_kbnote
2S1_cold_tailsmall394947161000246.04014408tail page=100
3S2_warm_tailsmall394947161000233.87814716tail page=100
4S3_deep_paginationsmall39494716100021.02414716n_pages=1000
5S4_first_buildsmall394947161000239.13914716idx_entries=20
6S5_incremental_extendsmall10441110000.85914716appended=1000_lines
7S6_verifysmall3949471610002396.02216424total=1 err=0 warn=1 info=0
8L1longmsg1105861001.4869432n=100 body=1024 write=0.8ms read=0.6ms parsed=100 mismatch=0 parse_fail=0 1KB body x100
9L2longmsg103218610010.4689432n=100 body=10240 write=5.7ms read=4.8ms parsed=100 mismatch=0 parse_fail=0 10KB body x100
10L3longmsg10248186100100.3379816n=100 body=102400 write=57.3ms read=43.1ms parsed=100 mismatch=0 parse_fail=0 100KB body x100
11L4longmsg5243293650502.78513608n=50 body=1048576 write=264.5ms read=238.3ms parsed=50 mismatch=0 parse_fail=0 1MB body x50
12L5longmsg5242969610518.55827764n=10 body=5242880 write=264.4ms read=254.2ms parsed=10 mismatch=0 parse_fail=0 5MB body x10
13L6longmsg414355524407.80345852n=4 body=10358784 write=211.3ms read=196.5ms parsed=4 mismatch=0 parse_fail=0 9.9MB body x4 (just under FF_MAX_LINE_LEN)
14L7longmsg1048598123.75045852oversize=10485761_rejected=yes read=3.8ms parsed=1
15L8longmsg51752865045.54945852n=50 body=102400 write=26.6ms read=18.9ms parsed=50 mismatch=0 parse_fail=0 100KB body w/ \n every 100B
16L9longmsg51241365045.48745852n=50 body=102400 write=24.5ms read=21.0ms parsed=50 mismatch=0 parse_fail=0 100KB body w/ pipes
17L10longmsg51241365043.25445852n=50 body=102400 write=18.9ms read=24.4ms parsed=50 mismatch=0 parse_fail=0 100KB body utf-8 emoji
18L11longmsg1105861001.28445852n=100 body=1024 write=0.7ms read=0.6ms parsed=100 mismatch=0 parse_fail=0 sanity baseline
19L12longmsg5415366100026.437458525x1MB_in_last_100 parsed=1000
20L13longmsg104865786100932.63045852n=100 body=1048576 write=485.7ms read=446.9ms parsed=100 mismatch=0 parse_fail=0 verify-equiv full parse on 100x1MB
21L14longmsg1024819861000962.34245852n=1000 body=102400 write=510.4ms read=452.0ms parsed=1000 mismatch=0 parse_fail=0 rapid append 1000x100KB
22F1fail-pass90400.1189540issues total=1 err=0 warn=1 (partial-line tail; expect graceful handle)
23F2fail-pass111900.1139540warnings=2 (expect CRLF warning) first_warn=File permissions are 644 expected 600 (sensitive data)
24F3fail-pass34100.0729540errors=1 warnings=1 (expect 1 unparsable line for mid-file BOM) first=Unparsable line
25F7fail-pass52700.0829540issues total=1 err=0 (cycle handled at read-time not verify)
26F8fail-pass1904400.9819540201 lines (1 orig + 200 corrections) errors=0 warns=1
27F9fail-pass34100.0699540errors=0 (parser splits at first ': ' — not flagged but body truncated)
28F10fail-pass17600.0609540errors=0 warnings=1 (RTL/ZWSP preserved literally)
29F11fail-pass32300.2649540errors=1 (Latin-1 byte: error or fallback OK)
30F12fail-pass33000.0719540errors=0 (empty body OK)
31F14fail-pass2323600.9149540v1_lines=100 v2_lines=250 (expect rebuild detected and 250 lines)
32F15fail-pass000.1219540errors=0 infos=1 warnings=1 (empty file should yield INFO)
33S1_cold_taillmc389183687100002480.42843456tail page=100
34S2_warm_taillmc389183687100002477.48243456tail page=100
35S3_deep_paginationlmc3891836871000021.06643456n_pages=1000
36S4_first_buildlmc389183687100002473.60443456idx_entries=200
37S5_incremental_extendlmc10441110000.90243456appended=1000_lines
38S6_verifylmc3891836871000023892.13743456total=1 err=0 warn=1 info=0
39S6_verifyooo3975867201000024037.05833336total=17573 err=0 warn=17573 info=0
40S7a_export_coldpipe100000407142401000003925.249148432exported=100000 db_rows=100000
41S7b_export_deduppipe100000407142401000003884.913252396exported=0 db_rows=100000
42S7_seed_exportpipe100000407142401000003894.644148320exported=100000 db_rows=100000
43S8a_import_coldpipe100000406282241000003162.988123212imported=100000 rows_before=0 rows_after=100000
44S8b_import_idempotentpipe1000004062822401178.929194896imported=0 rows_before=100000 rows_after=100000
45S8e_roundtrippipe100000405217281000008905.553148340rows=100000 seed=1640ms export=3730ms import=3258ms diff=277ms exported=100000 imported=100000 rows_a=100000 rows_b=100000 mismatches=0 body=0 lmc=0
46S7a_export_coldpipe10000004077322241000000309245.3021376872exported=1000000 db_rows=1000000
47S7b_export_deduppipe10000004077322241000000303526.6382418088exported=0 db_rows=1000000
48S7_seed_exportpipe10000004077322241000000304160.0431377084exported=1000000 db_rows=1000000
49S8a_import_coldpipe1000000406605824100000031288.2881124984imported=1000000 rows_before=0 rows_after=1000000
50S8b_import_idempotentpipe1000000406605824010418.8501841644imported=0 rows_before=1000000 rows_after=1000000
51S8e_roundtrippipe10000004057579521000000352840.0261377148rows=1000000 seed=17637ms export=301062ms import=31430ms diff=2711ms exported=1000000 imported=1000000 rows_a=1000000 rows_b=1000000 mismatches=0 body=0 lmc=0