-
Notifications
You must be signed in to change notification settings - Fork 412
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Performance: Trace file shows Source tree scan
stage takes 38+ seconds
#10880
Comments
@jchavarri , are your sources in this case stored on some kind of networked file system? |
No, they are local. The only non-conventional thing of this setup is that the build is running in a remote machine that I access through ssh. |
I see, thanks. |
I can share
I doubt it will give us a lot of insights. It seems time is mostly spent on |
From memory I remember that the "Source tree scan" event actually englobes the whole build; ie the actual build commands are sub-events of "Source tree scan", so the 38+ s that you are observing may just be the build doing its thing. Does it make sense? |
@ejgallego Here's the output of
@nojb This is a "noop" build (all build commands already happened in previous runs of (thanks both for your input!) |
Yes, in fact |
It does not generate the rules, but it does initialize all the projects, constructs the scopes, and parses every dune file. |
Some |
Here it is: |
Maybe the result of this issue could be to rename this stage to "Project initialization, scope construction, dune parsing" instead of "Source tree scan". Does that make sense? |
It would be more accurate. I can't read your perf file unfortunately |
Try loading it in https://profiler.firefox.com/ |
Thanks, that works. I do see a lot of rule generation in that trace. Are you using dynamic includes perhaps? |
We use atd a lot, so we have a bunch of
Do you think this could be causing trouble? I can look into optimizing these to try to reduce the number of rules. |
Side note: curious what kind of things you look at on the Firefox profiler to reach this kind of conclusion. What kind of views do you use? And what led you realize rule generation could be the issue? Thanks! |
Edit: ignore this comment, I was measuring wrongly 😕
with open("dune", "w") as dune_file:
for i in range(1, 50001):
dune_file.write("""
(rule
(targets {0}.txt)
(action (write-file {0}.txt "This is file {0}")))
""".format(i))
print("dune file generated with 50000 rules.") with open("dune", "w") as dune_file:
for i in range(1, 50001):
dune_file.write("""
(rule
(targets {0}.txt)
(action (with-stdout-to {0}.txt (echo "This is file {0}"))))
""".format(i))
print("dune file generated with 50000 rules.") |
I saw the load_rules function in the trace which invokes the various rule generation callbacks. Even though your measurement is incorrect, we have in fact sped up reading and writing of files and that let to a noticeable speed up in dune internally. Don't get your hopes too high though, I'd imagine this will shave off a few seconds - not much more. |
In case it helps, I managed to get a profile including src lines for the function calls to the actual Dune code. For backtracking these, the commit used is a054882. Unfortunately Firefox Profiler doesn't support srclines, it has to be opened with https://www.speedscope.app/. Make sure to choose dune_build_feall_aa_srclines.perf.zip |
Thanks for the updated trace. It mostly points to things that we've already known to be problematic. We've fixed them in our fork, but the truth is that that they might make your build at most 2x faster. So in total, we're looking at 19 seconds instead of 38. I doubt that will make you happy. Of course more optimizations are possible, and you're welcome to try to implement them. There's not much low hanging fruit though, so it will take real engineering work to shave off more seconds beyond that. Feel free to open tickets with traces for more concrete bottlenecks that you've detected. This issue is too general to be actionable. Source scanning isn't slow, it's just doing a bunch of work in your specific build. I don't have any concrete ideas on how to make it faster or delay some of the work. Suggestions are very much welcome. |
@rgrinberg out of curiosity, whose fork is this? Jane Street? Tarides? Are these improvements going to be merged back upstream eventually? Thanks! |
JS. We're planning to merge them bit by bit starting this year. |
It definitely does make me happy :) That would be a great improvement. I think if we combine that with some specific internal actions as well (mostly simplify the amount of explicit Looking forward to test any of the improvements as they get merged upstream. Thanks! |
We continue trying to figure out in which ways we could optimize our Dune build setup at Ahrefs.
One of the things that quickly stands out is that when enabling
--trace-file
, we can see that the "Source tree scan" step of folder.
takes more than 38s.One of the instances of the
Source tree scan
events shows the folderbackend/api/src
, which takes ~37s. But after that event, there's only very short lived events which don't add much information.Is there any way in which we could modify Dune to get more granular information about where the time is being spent? For example, if would be interesting to know if this time is spent parsing rules (of which
dune
files), executing commands that generatesexp
files, etc. If those things is something that can happen during theSource tree scan
stage, of course.Please find below the trace file (obtained with
dune build @fe.all @aa --trace-file fe.all-aa.txt
) and a screenshot loading the trace in Brave (Chrome-like browser):dune-build-fe.all-aa-trace.txt
Specifications
dune
:3.15.0
ocaml
:4.14.0
The text was updated successfully, but these errors were encountered: