Skip to content

perf: cache filtered include flags per [(lib_mode, kept_libs)]#14519

Draft
robinbb wants to merge 1 commit into
robinbb-14492-l6-filtered-include-flagsfrom
robinbb-14492-l7-filtered-includes-cache
Draft

perf: cache filtered include flags per [(lib_mode, kept_libs)]#14519
robinbb wants to merge 1 commit into
robinbb-14492-l6-filtered-include-flagsfrom
robinbb-14492-l7-filtered-includes-cache

Conversation

@robinbb
Copy link
Copy Markdown
Collaborator

@robinbb robinbb commented May 13, 2026

Layer 7 of 9 of #14492. Pure performance.

Compilation_context.Filtered_includes caches the Action_builder.t returned by filtered_include_flags keyed on (lib_mode, kept_libs). Two modules in the same cctx that reach the same set of kept libs share one builder; Action_builder.memoize dedupes its evaluation.

Lib_mode.hash: new — used by the cache key.

Stack: rebases on #14518. Next: #14520.

Part of #14492. Related to #4572.

@robinbb robinbb self-assigned this May 13, 2026
@robinbb robinbb force-pushed the robinbb-14492-l6-filtered-include-flags branch from c50afa4 to 38a7871 Compare May 14, 2026 00:36
@robinbb robinbb force-pushed the robinbb-14492-l7-filtered-includes-cache branch 2 times, most recently from d0903f5 to 7205127 Compare May 14, 2026 23:57
[Compilation_context.Filtered_includes] caches the [Action_builder.t]
returned by [filtered_include_flags] keyed on
[(lib_mode, kept_libs)]. Two modules in the same cctx that reach the
same set of kept libs share one builder; [Action_builder.memoize]
dedupes its evaluation.

Cache key omits the cctx's [requires_compile] / [requires_hidden] —
they're immutable on the cctx from [create]. The
[for_module_generated_at_link_time] exception, where derived cctxs
could in principle alter the closure, takes [can_filter = false] in
[lib_deps_for_module] and so never reaches this function.

[Filtered_includes.Key]: [lib_mode] + [kept_libs : Lib.t list] (the
caller passes a sorted list via [Lib.Set.to_list], canonicalising for
the cache). [equal] and [hash] derived from the same; [Repr]-derived
[to_dyn] for diagnostics.

[Lib_mode.hash]: new — used by [Filtered_includes.Key.hash]. Three
constants for the three variants ([Ocaml Byte], [Ocaml Native],
[Melange]).

Signed-off-by: Robin Bate Boerop <me@robinbb.com>
@robinbb robinbb force-pushed the robinbb-14492-l6-filtered-include-flags branch from 38a7871 to 8634a30 Compare May 15, 2026 02:57
@robinbb robinbb force-pushed the robinbb-14492-l7-filtered-includes-cache branch from 7205127 to e28b521 Compare May 15, 2026 02:57
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