Commit 93a528b
committed
perf: cache the per-(dep_m, ml_kind, cm_kind, is_consumer) raw-refs builder
In [module_compilation.ml]'s [lib_deps_for_module], each consumer
module iterates over [m :: trans_deps] and calls [read_dep_m_raw]
per dep. Sibling consumers in the same stanza share large parts
of [trans_deps] but used to reconstruct fresh [Action_builder.t]
trees per call — the inner [ocamldep] result is shared via
[Ocamldep]'s path-keyed cache, but the wrapping
[need_impl_deps_of] / [Module_name.Set.union] logic was rebuilt
N×K times per stanza.
Add a per-cctx [Raw_refs.t = (Key.t, _ Action_builder.t) Table.t]
in [Compilation_context], keyed on
(obj_name, ml_kind, cm_kind, is_consumer). [Table.find]
short-circuits before allocating, mirroring the pattern used by
[Ocamldep.read_immediate_deps_words]'s top-level cache. Two prior
attempts at this memoisation failed:
* Apr 21 (`e1b638664`, reverted): recursive memo across direct
module deps; infinite loop on module-level cycles
(`alias/check-alias/ocamldep-cycles.t`).
* Apr 25 (`3a70bfaa0`, dropped): seen-set shape; OOM-killed
CI because [Action_builder.memoize] dedupes evaluation by
string key but does NOT dedupe construction. With N modules
× M consumers, each call still allocated a fresh
[Action_builder.t] tree before the memoize wrapper saw the
key.
This third attempt avoids both failure modes: the [Table.find]
short-circuit prevents construction-time blowup, and the cache
is intra-stanza only (the cross-library walk has its own
[seen]-set termination), so module-level cycles are not visited
by this loop.
Addresses art-w's review concern at
https://github.com/ocaml/dune/pull/14116/files#r3116025155
Signed-off-by: Robin Bate Boerop <me@robinbb.com>1 parent 1e0dfeb commit 93a528b
3 files changed
Lines changed: 121 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
40 | 100 | | |
41 | 101 | | |
42 | 102 | | |
| |||
113 | 173 | | |
114 | 174 | | |
115 | 175 | | |
| 176 | + | |
116 | 177 | | |
117 | 178 | | |
118 | 179 | | |
| |||
377 | 438 | | |
378 | 439 | | |
379 | 440 | | |
| 441 | + | |
380 | 442 | | |
381 | 443 | | |
382 | 444 | | |
383 | 445 | | |
384 | 446 | | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
385 | 459 | | |
386 | 460 | | |
387 | 461 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
67 | 82 | | |
68 | 83 | | |
69 | 84 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
122 | 122 | | |
123 | 123 | | |
124 | 124 | | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
140 | 157 | | |
141 | 158 | | |
142 | 159 | | |
| |||
0 commit comments