|
| 1 | +# Optimization Workflow |
| 2 | + |
| 3 | +The goal is to make the parser faster without letting the implementation turn |
| 4 | +into clever, brittle code. Every optimization should carry both a speed result |
| 5 | +and a readability/maintenance result. |
| 6 | + |
| 7 | +## Baseline |
| 8 | + |
| 9 | +Build the optimization harness with release flags: |
| 10 | + |
| 11 | +```sh |
| 12 | +clang++ -std=c++11 -O2 -DNDEBUG -g -fno-omit-frame-pointer \ |
| 13 | + benchmark/optimize.cpp -I. -o /tmp/aria_csv_optimize |
| 14 | +``` |
| 15 | + |
| 16 | +Run a baseline: |
| 17 | + |
| 18 | +```sh |
| 19 | +/tmp/aria_csv_optimize 7 | tee benchmark/baseline.csv |
| 20 | +``` |
| 21 | + |
| 22 | +The harness prints CSV: |
| 23 | + |
| 24 | +```text |
| 25 | +workload,mode,bytes,iterations,best_ms,mb_per_s,checksum |
| 26 | +``` |
| 27 | + |
| 28 | +Use the best time across iterations to reduce scheduler noise. Re-run the |
| 29 | +baseline before comparing a change if the machine load changed noticeably. |
| 30 | + |
| 31 | +## Workloads |
| 32 | + |
| 33 | +The harness generates four in-memory workloads: |
| 34 | + |
| 35 | +- `plain`: common unquoted rows with many ordinary fields. |
| 36 | +- `quoted`: quoted fields, escaped quotes, commas, and embedded newlines. |
| 37 | +- `wide`: many small columns per row. |
| 38 | +- `huge-fields`: fields larger than the parser's input buffer. |
| 39 | + |
| 40 | +Each workload runs through both public APIs: |
| 41 | + |
| 42 | +- `fields`: direct `next_field()` parsing. |
| 43 | +- `rows`: range iteration over rows. |
| 44 | + |
| 45 | +## Change Gate |
| 46 | + |
| 47 | +For each optimization, record: |
| 48 | + |
| 49 | +- the exact code change |
| 50 | +- baseline and after numbers |
| 51 | +- percent speed change per workload |
| 52 | +- test/fuzz/property status |
| 53 | +- readability score |
| 54 | +- decision: keep, revise, or revert |
| 55 | + |
| 56 | +Suggested readability score: |
| 57 | + |
| 58 | +- `1`: simpler than before |
| 59 | +- `2`: same complexity |
| 60 | +- `3`: slightly more complex but local and well named |
| 61 | +- `4`: noticeably harder to maintain |
| 62 | +- `5`: too clever for this project |
| 63 | + |
| 64 | +Default policy: keep only changes that improve at least one target workload by |
| 65 | +5% or more, do not regress any major workload by more than 2%, and score `3` or |
| 66 | +better on readability. |
| 67 | + |
| 68 | +Compare two runs with: |
| 69 | + |
| 70 | +```sh |
| 71 | +python3 benchmark/compare_results.py benchmark/baseline.csv benchmark/after.csv |
| 72 | +``` |
| 73 | + |
| 74 | +The comparison script also checks that workload checksums did not change. A |
| 75 | +checksum change means the parser behavior changed or the benchmark changed, so |
| 76 | +the result is not a pure performance comparison. |
| 77 | + |
| 78 | +## Verification |
| 79 | + |
| 80 | +Before keeping a performance change, run: |
| 81 | + |
| 82 | +```sh |
| 83 | +cmake -S test -B /tmp/aria_csv_test |
| 84 | +cmake --build /tmp/aria_csv_test --parallel |
| 85 | +/tmp/aria_csv_test/parser_test |
| 86 | + |
| 87 | +cmake -S test -B /tmp/aria_csv_property -DARIA_CSV_ENABLE_PROPERTY_TESTS=ON |
| 88 | +cmake --build /tmp/aria_csv_property --parallel |
| 89 | +/tmp/aria_csv_property/parser_property_test |
| 90 | + |
| 91 | +clang++ -std=c++11 -Wall -Wextra -pedantic -I. \ |
| 92 | + -fsanitize=fuzzer-no-link,address,undefined \ |
| 93 | + -c fuzz/libfuzzer_parser.cpp -o /tmp/aria_csv_libfuzzer.o |
| 94 | +``` |
| 95 | + |
| 96 | +Run the sampling profiler when a change meaningfully moves benchmark numbers: |
| 97 | + |
| 98 | +```sh |
| 99 | +clang++ -std=c++11 -O2 -g -fno-omit-frame-pointer \ |
| 100 | + benchmark/profile.cpp -I. -o /tmp/aria_csv_profile |
| 101 | + |
| 102 | +/tmp/aria_csv_profile benchmark/sample.csv 8000 & |
| 103 | +pid=$! |
| 104 | +sample "$pid" 3 1 -file /tmp/aria_csv_profile.sample.txt |
| 105 | +wait "$pid" |
| 106 | +``` |
| 107 | + |
| 108 | +## Decision Record Template |
| 109 | + |
| 110 | +```md |
| 111 | +## YYYY-MM-DD: <change name> |
| 112 | + |
| 113 | +Hypothesis: |
| 114 | + |
| 115 | +Change: |
| 116 | + |
| 117 | +Benchmark: |
| 118 | + |
| 119 | +| workload | mode | baseline MB/s | after MB/s | delta | |
| 120 | +| --- | --- | ---: | ---: | ---: | |
| 121 | + |
| 122 | +Verification: |
| 123 | + |
| 124 | +Readability score: |
| 125 | + |
| 126 | +Decision: |
| 127 | +``` |
0 commit comments