Skip to content

pkg: on dune build start, lock dir parsing is slow #12248

@v-gb

Description

@v-gb

Currently, a null build in my tiny repo is surprisingly slow (8s).

A significant fraction of that is caused by sexp parsing of the lock dir, specifically the fact that the error path of some combinators like Dune_sexp.Decoder.find_cstr is expensive (due to User_message.did_you_mean), and that Dune_sexp.Decoder.either means you can run a ton of error paths, instead of just one as would be normal.

With these depends in my dune-project:

(package
  ...
 (depends
   ocaml
   core
   core_unix
   markup
   uri
   uucp
   yojson
   http-lwt-client
   ppx_yojson_conv
   ppx_sexp_value
   ppx_sexp_conv
   ppx_compare
   ppx_hash
   ppx_pipebang
   ppx_let
   ppx_bin_prot
   ppx_partial
   lwt_ppx
   ocamlformat
 ))

I observe this:

$ time ~/code/dune/_build/default/bin/main.exe build --display=quiet

real 0m7,809s
user 0m7,363s
sys 0m0,450s

but when I comment out all the ~hints from Dune_sexp.Decoder:

$ time ~/code/dune/_build/default/bin/main.exe build --display=quiet

real 0m4,960s
user 0m4,512s
sys 0m0,450s

It seems to me that either the sexp decoding module shouldn't backtrack, or the errors should be lazy, i.e. only computed on display.

(even with that, the performance seems off by an order of magnitude, possibly two. There's 130kB of data in the lock dirs and 1 dune file and 2 .ml file. It's wild that this takes any noticeable time at all)

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions