Skip to content

Look up the cases of a suite in linear time - #482

Merged
samoht merged 2 commits into
mirage:mainfrom
samoht:fix-case-lookup
Nov 12, 2026
Merged

samoht merged 2 commits into
mirage:mainfrom
samoht:fix-case-lookup

Conversation

@samoht

@samoht samoht commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

Since #451, Alcotest records the location of each test case in a table grouped by case name. Each case keeps its own entry: lookups compare the case value itself, so two cases with the same name are told apart. But finding a case scans every entry with its name, so a suite where many cases share a name, such as one generated from test vectors, was quadratic: listing 40,000 cases all named "v" took 5.6s, against 0.35s with distinct names.

Cases are almost always looked up in the order they were created, or in reverse order for a list literal. The lookup now tries the entries next to the previous match before scanning, so the same 40,000 cases take 0.29s.

@samoht
samoht force-pushed the fix-case-lookup branch 5 times, most recently from d3aad20 to 244bbda Compare November 12, 2026 12:33
Since 1.10.0, compiling a suite looked up each case twice in the list
of every case created with the same name, so a suite of many cases
with the same name, as in a suite built from test vectors, was
quadratic: 40,000 cases named "v" took 5.6s to list, against 0.35s
with distinct names.

The cases of a suite come in the order they were created in, or in the
reverse order for a list literal, so a lookup now tries the neighbours
of the previous one before scanning, and each case is looked up once.
The same 40,000 cases now take 0.29s, in either order.
@samoht
samoht merged commit a76220b into mirage:main Nov 12, 2026
7 checks passed
@samoht
samoht deleted the fix-case-lookup branch November 12, 2026 14:24
jmid pushed a commit to ocaml/opam-repository that referenced this pull request Nov 17, 2026
CHANGES:

- Fix parallel test runs failing with `Failed 6 times to create symlink`, and
  a dangling `latest` link (mirage/alcotest#479, @samoht, fixes mirage/alcotest#471 and mirage/alcotest#472 in 1.10.0)
- Fix tests failing with `EACCES` on a read-only source tree or with
  `DUNE_BUILD_DIR` (mirage/alcotest#480, @samoht, fixes mirage/alcotest#471 in 1.10.0)
- Honour `ALCOTEST_SOURCE_CODE_POSITION` when set by the program before `run`
  (mirage/alcotest#481, @samoht, fixes mirage/alcotest#451 in 1.10.0)
- Fix slow runs of suites with many cases of the same name (mirage/alcotest#482, @samoht,
  fixes mirage/alcotest#451 in 1.10.0)
- Under Eio, point the failure locations added in 1.10.0 (mirage/alcotest#451) at the test,
  not at the scheduler (mirage/alcotest#484, fixes mirage/alcotest#478, @samoht, report by @talex5)
- Point a failed `check` in a helper at the `check`, as in 1.9.1, not at the
  test that calls the helper (mirage/alcotest#488, @samoht, fixes mirage/alcotest#451 in 1.10.0)
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