Skip to content

Try harder to not recompile sketch without modifications. #2961

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

cmaglie
Copy link
Member

@cmaglie cmaglie commented Jul 29, 2025

Please check if the PR fulfills these requirements

See how to contribute

  • The PR has no duplicates (please search among the Pull Requests
    before creating one)
  • The PR follows
    our contributing guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • UPGRADING.md has been updated with a migration guide (for breaking changes)
  • configuration.schema.json updated if new parameters are added.

What kind of change does this PR introduce?

Improves the checks made to the sketch to avoid useless recompilation and preprocessing.

What is the current behavior?

The sketch source code, before being compiled, undergoes a two-phase processing:

  1. If the sketch has multiple source files, these files are merged, forming a single .cpp file.
  2. The merged .cpp file is then "preprocessed" to automatically obtain the forward declarations of the functions defined in the sketch.

Previously, these two operations were always performed, touching the final sketch.cpp. This resulted in sketch.cpp being recompiled every time. Moreover, the library discovery cache could not be exploited because of the sketch.cpp timestamp change.

What is the new behavior?

The merged sketch file is saved in a separate sketch.cpp.merged file, and it is compared to the newly generated content. If they match, the already preprocessed sketch.cpp and sketch.cpp.merged are left untouched.
This is enough for the current build system to recognize that the file is already up-to-date and skip both compilation and library discovery, which greatly improves compile times.

Does this PR introduce a breaking change, and is titled accordingly?

Unless I'm missing some convoluted case, it shouldn't.

Other information

@cmaglie cmaglie self-assigned this Jul 29, 2025
@cmaglie cmaglie added type: enhancement Proposed improvement topic: build-process Related to the sketch build process labels Jul 29, 2025
@cmaglie cmaglie force-pushed the do-not-recompile-sketch branch from 755cb52 to 18335b6 Compare July 29, 2025 15:31
@cmaglie cmaglie force-pushed the do-not-recompile-sketch branch from 18335b6 to aa33373 Compare July 29, 2025 15:33
Copy link

codecov bot commented Jul 29, 2025

Codecov Report

❌ Patch coverage is 73.07692% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 68.27%. Comparing base (cba02e8) to head (aa33373).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...nal/arduino/builder/internal/preprocessor/ctags.go 71.42% 1 Missing and 3 partials ⚠️
internal/arduino/builder/sketch.go 72.72% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2961      +/-   ##
==========================================
+ Coverage   68.22%   68.27%   +0.04%     
==========================================
  Files         241      241              
  Lines       22696    22709      +13     
==========================================
+ Hits        15484    15504      +20     
+ Misses       6012     6006       -6     
+ Partials     1200     1199       -1     
Flag Coverage Δ
unit 68.27% <73.07%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: build-process Related to the sketch build process type: enhancement Proposed improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant