qsharp-compiler
qsharp-compiler copied to clipboard
Improve build time of Q# standard library and its tests
Describe the enhancement request
Currently building Q# Standard Library takes 55 seconds and building it together with tests takes 01:27. This might not seem like a long time for a language's standard library to build, however the number of lines of code in Q# standard library excluding comments and blank lines is 5303 ( measured for commit 55df2709294f27a55f286bab799d60ae81e829d3 ). Including tests there are 8376 lines of Q# code.
To Reproduce
For libraries build time:
git clone https://github.com/microsoft/QuantumLibraries.git
cd .\QuantumLibraries\Standard\src\
dotnet restore
dotnet build --no-restore
For tests
cd ..\tests\
dotnet restore
dotnet build --no-restore
Expected behavior
One would expect compiling around 5000 lines of Q# code into C# to be at least comparable in speed to compiling 5000 lines of C# code. Q# is a much simpler language than C# if you look at its syntax and type system, so one would expect that compiler for it should be at least as fast as C#.
System information
- OS: Windows
- .NET Core Version: 3.1.201
- Build is run on a dedicated SSD Samsung SSD 960 EVO 500 GB, separate from the SSD on which Windows is installed
- CPU: Intel(R) Core(TM) i7-7700T CPU @ 2.90GHz set to full performance
- 32 GB RAM
Additional context
Measuring number of lines excluding blank lines and comments
To count the number of lines we used cloc with the following language definition file:
Q#
filter rm_comments_in_strings " //
filter call_regexp_common C++
3rd_gen_scale 1.36
extension qs
end_of_line_continuation \\$
cloc can be installed on windows with choco install cloc.
See video showing build process. Notice that the build does not take full advantage of available memory and processor.
@vadym-kl Could you please add
<PropertyGroup>
<AdditionalQscArguments>--perf path</AdditionalQscArguments>
</PropertyGroup>
to the project, build it, and post the content of the file in path? That will give us additional information regarding where the time is spent.
Some improvements: https://github.com/microsoft/qsharp-compiler/pull/935
Is this still an issue? I just repeated the initial steps of building /Standard/src (with the --perf path addition) and the entire build took 21.6 seconds, with the actual build step being a touch under 15 seconds (full log below).
This is on my MSI laptop. While admittedly a nice laptop, that doesn't seem like an egregious amount of time for a clean build of the standard library.
If this is still unacceptable, let's define a clear goal to aim for, else we should close this bug. (Parity with C# isn't a realistic goal, as they have person-decades of investment in that compiler).
{
"OverallCompilation": 21633,
"OverallCompilation.Build": 14965,
"OverallCompilation.OutputGeneration": 310,
"OverallCompilation.OutputGeneration.BinaryGeneration": 4,
"OverallCompilation.OutputGeneration.SyntaxTreeSerialization": 305,
"OverallCompilation.ReferenceLoading": 169,
"OverallCompilation.ReferenceLoading.HeaderAttributesLoading[21]": 3,
"OverallCompilation.ReferenceLoading.HeaderAttributesLoading[6]": 3,
"OverallCompilation.ReferenceLoading.HeaderAttributesLoading[19]": 1,
"OverallCompilation.ReferenceLoading.HeaderAttributesLoading[11]": 1,
"OverallCompilation.ReferenceLoading.HeaderAttributesLoading[23]": 1,
"OverallCompilation.ReferenceLoading.HeaderAttributesLoading[4]": 1,
"OverallCompilation.ReferenceLoading.HeaderAttributesLoading[14]": 1,
"OverallCompilation.ReferenceLoading.HeaderAttributesLoading[24]": 1,
"OverallCompilation.ReferenceLoading.HeaderAttributesLoading[22]": 1,
"OverallCompilation.ReferenceLoading.HeaderAttributesLoading[8]": 1,
"OverallCompilation.ReferenceLoading.HeaderAttributesLoading[7]": 1,
"OverallCompilation.ReferenceLoading.HeaderAttributesLoading[25]": 1,
"OverallCompilation.ReferenceLoading.HeaderAttributesLoading[15]": 0,
"OverallCompilation.ReferenceLoading.HeaderAttributesLoading[16]": 0,
"OverallCompilation.ReferenceLoading.HeaderAttributesLoading[18]": 0,
"OverallCompilation.ReferenceLoading.HeaderAttributesLoading[17]": 0,
"OverallCompilation.ReferenceLoading.HeaderAttributesLoading[10]": 0,
"OverallCompilation.ReferenceLoading.LoadDataFromReferenceToStream[14]": 4,
"OverallCompilation.ReferenceLoading.LoadDataFromReferenceToStream[4]": 4,
"OverallCompilation.ReferenceLoading.LoadDataFromReferenceToStream[6]": 2,
"OverallCompilation.ReferenceLoading.LoadDataFromReferenceToStream[11]": 4,
"OverallCompilation.ReferenceLoading.LoadDataFromReferenceToStream[17]": 11,
"OverallCompilation.ReferenceLoading.LoadDataFromReferenceToStream[21]": 2,
"OverallCompilation.ReferenceLoading.LoadDataFromReferenceToStream[22]": 4,
"OverallCompilation.ReferenceLoading.LoadDataFromReferenceToStream[10]": 11,
"OverallCompilation.ReferenceLoading.LoadDataFromReferenceToStream[18]": 11,
"OverallCompilation.ReferenceLoading.LoadDataFromReferenceToStream[12]": 14,
"OverallCompilation.ReferenceLoading.LoadDataFromReferenceToStream[16]": 11,
"OverallCompilation.ReferenceLoading.LoadDataFromReferenceToStream[19]": 4,
"OverallCompilation.ReferenceLoading.LoadDataFromReferenceToStream[8]": 4,
"OverallCompilation.ReferenceLoading.LoadDataFromReferenceToStream[13]": 24,
"OverallCompilation.ReferenceLoading.LoadDataFromReferenceToStream[23]": 4,
"OverallCompilation.ReferenceLoading.LoadDataFromReferenceToStream[20]": 29,
"OverallCompilation.ReferenceLoading.LoadDataFromReferenceToStream[25]": 4,
"OverallCompilation.ReferenceLoading.LoadDataFromReferenceToStream[15]": 11,
"OverallCompilation.ReferenceLoading.LoadDataFromReferenceToStream[24]": 4,
"OverallCompilation.ReferenceLoading.LoadDataFromReferenceToStream[7]": 4,
"OverallCompilation.ReferenceLoading.ReferenceHeadersCreation[4]": 2,
"OverallCompilation.ReferenceLoading.ReferenceHeadersCreation[7]": 2,
"OverallCompilation.ReferenceLoading.ReferenceHeadersCreation[19]": 2,
"OverallCompilation.ReferenceLoading.ReferenceHeadersCreation[8]": 2,
"OverallCompilation.ReferenceLoading.ReferenceHeadersCreation[24]": 2,
"OverallCompilation.ReferenceLoading.ReferenceHeadersCreation[22]": 2,
"OverallCompilation.ReferenceLoading.ReferenceHeadersCreation[25]": 2,
"OverallCompilation.ReferenceLoading.ReferenceHeadersCreation[6]": 2,
"OverallCompilation.ReferenceLoading.ReferenceHeadersCreation[23]": 2,
"OverallCompilation.ReferenceLoading.ReferenceHeadersCreation[14]": 2,
"OverallCompilation.ReferenceLoading.ReferenceHeadersCreation[11]": 2,
"OverallCompilation.ReferenceLoading.ReferenceHeadersCreation[21]": 2,
"OverallCompilation.ReferenceLoading.ReferenceHeadersCreation[15]": 0,
"OverallCompilation.ReferenceLoading.ReferenceHeadersCreation[16]": 0,
"OverallCompilation.ReferenceLoading.ReferenceHeadersCreation[18]": 0,
"OverallCompilation.ReferenceLoading.ReferenceHeadersCreation[17]": 0,
"OverallCompilation.ReferenceLoading.ReferenceHeadersCreation[10]": 0,
"OverallCompilation.ReferenceLoading.ReferenceHeadersCreation[12]": 9,
"OverallCompilation.ReferenceLoading.ReferenceHeadersCreation[13]": 0,
"OverallCompilation.ReferenceLoading.ReferenceHeadersCreation[20]": 0,
"OverallCompilation.ReferenceLoading.SyntaxTreeDeserialization[12]": 72,
"OverallCompilation.ReferenceLoading.SyntaxTreeDeserialization[13]": 118,
"OverallCompilation.ReferenceLoading.SyntaxTreeDeserialization[20]": 125,
"OverallCompilation.RewriteSteps": 5008,
"OverallCompilation.RewriteSteps.SingleRewriteStep-CapabilityInference": 258,
"OverallCompilation.RewriteSteps.SingleRewriteStep-ConjugationInlining": 21,
"OverallCompilation.RewriteSteps.SingleRewriteStep-CSharpGeneration": 3869,
"OverallCompilation.RewriteSteps.SingleRewriteStep-DocumentationGeneration": 665,
"OverallCompilation.RewriteSteps.SingleRewriteStep-FunctorGeneration": 84,
"OverallCompilation.RewriteSteps.SingleRewriteStep-LiftLambdas": 98,
"OverallCompilation.SourcesLoading": 1077
}