[Build] Add per-file up-to-date check in CompileNativeAssembly#11055
Draft
davidnguyen-tech wants to merge 2 commits intodotnet:mainfrom
Draft
[Build] Add per-file up-to-date check in CompileNativeAssembly#11055davidnguyen-tech wants to merge 2 commits intodotnet:mainfrom
davidnguyen-tech wants to merge 2 commits intodotnet:mainfrom
Conversation
When _CompileNativeAssemblySources runs, it recompiles ALL .ll files even if only some have changed. This is because MSBuild's target-level Inputs/Outputs is all-or-nothing — if any .ll file is newer than any .o file, every file gets recompiled. Add a per-file timestamp check in RunAssembler() — if the output .o is newer than the input .ll, that file is skipped. This saves time on incremental CoreCLR builds where upstream generators use CopyIfStreamChanged to preserve .ll timestamps for unchanged files. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add CompileNativeAssemblySourcesSkipsUnchangedFiles integration test that verifies on incremental CoreCLR builds, unchanged .ll files are not recompiled by the CompileNativeAssembly task while changed .ll files are still correctly compiled. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
41fdedd to
f644fca
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds per-file timestamp comparison in the
CompileNativeAssemblytask to skip recompilation of.llfiles whose.ooutput is already up-to-date. This avoids unnecessaryllcinvocations on incremental CoreCLR builds.Problem
_CompileNativeAssemblySourcesrecompiles ALL.ll→.ofiles whenever ANY.llfile changes, because MSBuild's target-levelInputs/Outputsis all-or-nothing. On incremental CoreCLR builds, upstream generators already useFiles.CopyIfStreamChangedto preserve timestamps on unchanged.llfiles, but theCompileNativeAssemblytask has no per-file granularity — it recompiles everything when the target runs.Fix
Before running
llcfor each source file inRunAssembler(), check if the output.ofile exists and its timestamp is ≥ the input.llfile's timestamp. If so, skip that file and emit a debug log message.This preserves parallel compilation of changed files while skipping unchanged ones individually.
Expected Savings
On incremental CoreCLR builds where only typemaps change (due to assembly MVID changes), other
.llfiles (environment, marshal_methods, jni_remap) are skipped, saving roughly 50-70% of the ~2.85s_CompileNativeAssemblySourcescost.Testing
CompileNativeAssemblySourcesSkipsUnchangedFilesintegration test that verifies:_CompileNativeAssemblySourcestarget still runs (not skipped at target level).llfile is skipped at the per-file level (via log message assertion)