Skip to content

Conversation

gridbugs
Copy link
Collaborator

To parse both portable and non-portable lockdirs with mostly the same code, the parser would attempt to parse fields with the non-portable lockdir syntax and fall back to the portable syntax should parsing fail. This led to the generation of parse errors when the first attempt at parsing a field would fail, and even though these errors are discarded, generating them took a noticeable amount of time.

This changes the parsing logic to only attempt to parse fields in a single syntax, determined by the presence of the solved_for_platforms field in the lockdir metadata file. This field is present precisely when a lockdir is portable.

Fixes #12248

Copy link
Member

@rgrinberg rgrinberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. 3.9s is still rather slow though. I think there should be more low hanging fruit to optimize here.

@v-gb
Copy link
Contributor

v-gb commented Sep 23, 2025

LGTM. 3.9s is still rather slow though. I think there should be more low hanging fruit to optimize here.

Indeed. In the issue, I wrote down my investigation of the remaining slowness.

@rgrinberg
Copy link
Member

Thanks for the thorough investigation. Do you want to send PR's for those fixes? Seems a bit silly if I am just going to redo the work from your notes.

To parse both portable and non-portable lockdirs with mostly the same
code, the parser would attempt to parse fields with the non-portable
lockdir syntax and fall back to the portable syntax should parsing fail.
This led to the generation of parse errors when the first attempt at
parsing a field would fail, and even though these errors are discarded,
generating them took a noticeable amount of time.

This changes the parsing logic to only attempt to parse fields in a
single syntax, determined by the presence of the `solved_for_platforms`
field in the lockdir metadata file. This field is present precisely when
a lockdir is portable.

Signed-off-by: Stephen Sherratt <[email protected]>
@gridbugs gridbugs merged commit 1c4e309 into ocaml:main Sep 24, 2025
23 of 25 checks passed
@gridbugs gridbugs deleted the fix-gh12248 branch September 24, 2025 01:27
@v-gb
Copy link
Contributor

v-gb commented Sep 29, 2025

Thanks for the thorough investigation. Do you want to send PR's for those fixes? Seems a bit silly if I am just going to redo the work from your notes.

I sent the changes I have, but I don't have a broad understanding of the code, so while the changes are enough to prove that dune should be much faster, maybe some other change would be even better.

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.

pkg: on dune build start, lock dir parsing is slow
3 participants