- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 432
Improved compile speed by running multi-threaded library discovery. #2625
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
Conversation
f408819    to
    05c4745      
    Compare
  
    | Codecov ReportAttention: Patch coverage is  
 Additional details and impacted files@@            Coverage Diff             @@
##           master    #2625      +/-   ##
==========================================
+ Coverage   68.01%   68.22%   +0.21%     
==========================================
  Files         239      241       +2     
  Lines       22589    22696     +107     
==========================================
+ Hits        15363    15484     +121     
+ Misses       6023     6012      -11     
+ Partials     1203     1200       -3     
 Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
 | 
05c4745    to
    8afa7d8      
    Compare
  
    | LGTM | 
55ee2f5    to
    cc15358      
    Compare
  
    cc15358    to
    87765a4      
    Compare
  
    There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From my POV, is okay. I tested it on some sketches and I can see the improvement.
However, let's wait for some other users to gather feedback. (Just in case some edge cases arise).
87765a4    to
    9536817      
    Compare
  
    | Hi, I'm using Arduino IDE 2.x everyday on my open-source ReflectionsOS project. It's an ESP32-S3 board with a bunch of sensors. About 18,000 lines of code so far. Compiles on my MacBook Air M2 2022 8 Cores takes about 3-4 minutes. I'd be glad to spend time and money testing the PR. Would someone please give me instructions on how to get the PR code and compile the IDE for Mac? -Frank | 
a0a703f    to
    8913485      
    Compare
  
    | Hi @frankcohen, the instructions to test the PR are here: use the following link to download the latest version of the patched  | 
| Hi @cmaglie I would like to test this as well, as ResolveLibrary calls are taking >30s out of my 45 second compilation time. However, the artifacts have expired from that run, anyway to re-run the action and get new executables? | 
| Using gh gh repo clone arduino/arduino-cli
cd arduino-cli
gh pr checkout 2625
go build .Using git git clone https://github.com/cmaglie/arduino-cli.git
git checkout libs_detector_improvements
go build .Then you will find the arduino-cli` binary in the project's root dir, and you can use that to test. You'll need to have  | 
| Thanks Alessio, I was able to build and test this branch. Works great for me, I compiled all the projects I have with it, no issues. Compile times have reduced substantially, from 45 seconds in one esp32 project down to 15 seconds. | 
8913485    to
    1da775f      
    Compare
  
    There is no need to duplicate the preprocessResult/Err variables. This also simplifies naming making it more straighforward.
Also fixed the "low memory" warning printer.
The new release of the library allow ignoring the returned error. arduino/go-properties-orderedmap#42
It slightly simplifies code, but also provide the basis for the next commits.
1da775f    to
    7241f25      
    Compare
  
    
Please check if the PR fulfills these requirements
See how to contribute
before creating one)
our contributing guidelines
UPGRADING.mdhas been updated with a migration guide (for breaking changes)configuration.schema.jsonupdated if new parameters are added.What kind of change does this PR introduce?
This is a tentative to improve compile speed by multi-threading the library discovery phase.
How library discovery works
The library discovery is a sequential process, and could be summarized as follows:
gcc -E ...)Missing include file "xxx.h"error then:xxx.his added to the includes path listThe above loop continues until one of the following happens:
missing includeCould this be multi-threaded?
The main issue here is that each run of
gcc -E ...requires the includes path list determined by the previous iterations. At first sight, it seems a strictly sequential process.BTW, there are some strategies that we may use:
When a library is added to the queue, we may speculatively start a multithreaded compilation of the next files in the queue assuming no
missing includeerrors will be produced. Most of the time this assumption turns out to be true and the time saved could be dramatic.We may leverage the "library detection cache" to spawn a speculative multithreaded compilation of all the files (predicting all the libraries added in the process), assuming that the
missing includeerrors would be the same as the previous successful compilation as saved in the "library detection cache". In this case, we reproduce the same compiles as the previous build. The basic assumption is that the libraries detected will not change between compilations.If an unforeseen
missing includeerror is detected, the speculative multithreaded compilation must be canceled and restarted (basically wasting the work done ahead of time). In a multi-core system, since the work "ahead" is done in parallel, the worst-case scenario should take nearly the same time as the "classic" non-multithreaded compile.Due to the complexity of these changes, I'll start this as a draft. I want to add integration tests to trigger edge cases before merging.
What is the current behavior?
What is the new behavior?
Compiles should in general be faster than before.
Does this PR introduce a breaking change, and is titled accordingly?
No
Other information