这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@let-def
Copy link

@let-def let-def commented Sep 22, 2025

This PR has also been opened on upstream ocamlformat: ocaml-ppx#2724
I rebased it to oxcaml in priority to pave the way for efficient automated testing (@ccasin).


Command‑line parsing occurs in two passes: one pass parses the actions, and a second pass parses the configuration.
Because the configuration parser is invoked for every input file, the overall parsing time grows quadratically with the number of files.

This patch memoizes the configuration so that the parser runs only once. The configuration changes are still applied to each input file, preserving the original ocamlformat behaviour while making the runtime independent of the number of inputs.

Below are two plots that illustrate the performance before and after the change. They show the time spent and the number of stat calls as functions of the number of input files, clearly demonstrating the quadratic behaviour that the patch removes.

stat
time

There is only a single instance anyway.
Otherwise the config parser would run for every argument, resulting in
quadratic parsing.
Copy link

@ccasin ccasin left a comment

Choose a reason for hiding this comment

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

Thanks @let-def !

I'm approving since this was approved upstream, but will hold off on clicking merge until you have a moment to copy over the changes from the change from that review.

@let-def
Copy link
Author

let-def commented Sep 23, 2025

Done, thanks.

@ccasin ccasin merged commit 91b6df5 into oxcaml:jane Sep 23, 2025
2 checks passed
@let-def let-def deleted the jane-fix-quadratic-cmdline-parsing branch September 24, 2025 03:00
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.

2 participants