Add make perf and fd table constant lookup test
(This PR is built on top of #68. Please review/merge that one first)
This PR serve as the reference for https://github.com/sysprog21/kbox/issues/38#issuecomment-4415459055
Resolve test gap 3 in #38:
-
Add a
check-perfbuild target that compiles the unit test suite with-O2 -DKBOX_PERF_ONLYin a separate
binary (test-perf), keeping it independent from the check-unit artifact. Sanitizer and debug flags are stripped fromPERF_TEST_CFLAGSso timings reflect optimized production code. -
Add a benchmark that exercises
kbox_fd_table_find_by_host_fdfor both present and absent host FDs across table sizes {64, 256, 1024, 4096, 16384} and asserts that per-lookup latency stays within 2x of the N=64 baseline.
Results
--- O(1) Characteristic Perf Test ---
N = 64 | Present: 1.65 ns/op | Absent: 1.39 ns/op
N = 256 | Present: 1.87 ns/op | Absent: 1.38 ns/op
N = 1024 | Present: 1.60 ns/op | Absent: 1.29 ns/op
N = 4096 | Present: 1.63 ns/op | Absent: 1.31 ns/op
N = 16384 | Present: 1.59 ns/op | Absent: 1.39 ns/op
ok
The lookup time is flat across all table sizes — present lookups stay in the 1.59–1.87 ns range and absent lookups stay in the 1.29–1.39 ns range regardless of whether the table has 64 or 16384 entries, adhering to O(1) signature.
Summary by cubic
Adds a perf-only test runner (check-perf) and an O(1) reverse-lookup benchmark for the FD table, plus a fix that correctly downgrades MULTI mappings when aliases close. Covers test gap 3 in #38 and runs in CI without sanitizers to reflect production timing.
-
New Features
make check-perf: builds a separatetests/unit/test-perfwith-O2 -DKBOX_PERF_ONLY(no sanitizers/debug) so only perf benchmarks run; included inmake checkand a new CIperf-testsjob.- O(1) benchmark for
kbox_fd_table_find_by_host_fdacross {64, 256, 1024, 4096, 16384}; asserts present/absent lookups stay ≤2x the N=64 baseline.
-
Bug Fixes
- Add
host_fd_refs[]and updaterev_host_set/clearto maintain counts and downgrade fromMULTIto the surviving VFD when one alias remains; counters initialized inkbox_fd_table_init. - New regression test (
test-fd-table-refcount.c) ensures reverse lookup returns the survivor after other aliases close.
- Add