this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Avoid Format.asprintf in segment_to_string hot path

segment_to_string was called millions of times during HTML generation
(one of the top allocation sites: ~60% of minor heap allocation
according to statmemprof). It used Format.asprintf "%a%s" with a
pretty-printer that either does nothing (for Module/Page/LeafPage/
File/SourcePage kinds — the common case) or emits "<kind>-".

Replace with a direct match: return name unchanged for passthrough
kinds, otherwise concatenate prefix directly. Eliminates Format
buffer allocation per call.

Results:
- core.odocl html-generate: 45.7 GB -> 23.4 GB (-49% alloc)
- core.odocl html-generate: 9.53s -> 7.33s (-23%)
- stdlib.odocl html-generate: 1.74s -> 0.52s (-70%)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

+6 -1
+6 -1
src/html/link.ml
··· 7 7 let for_printing url = List.map snd @@ Url.Path.to_list url 8 8 9 9 let segment_to_string (kind, name) = 10 - Format.asprintf "%a%s" Url.Path.pp_disambiguating_prefix kind name 10 + (* Avoid Format.asprintf in the hot path. The disambiguating prefix is 11 + either empty (for Module/Page/LeafPage/File/SourcePage) or just 12 + "<kind>-", so build the result directly. *) 13 + match kind with 14 + | `Module | `Page | `LeafPage | `File | `SourcePage -> name 15 + | _ -> Url.Path.string_of_kind kind ^ "-" ^ name 11 16 12 17 let is_leaf_page url = url.Url.Path.kind = `LeafPage 13 18