{"id":25393,"date":"2020-01-29T15:00:58","date_gmt":"2020-01-29T15:00:58","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/cppblog\/?p=25393"},"modified":"2020-01-27T21:45:08","modified_gmt":"2020-01-27T21:45:08","slug":"improved-parallelism-in-msbuild","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/cppblog\/improved-parallelism-in-msbuild\/","title":{"rendered":"Improve Parallelism in MSBuild"},"content":{"rendered":"<p>Starting in Visual Studio 2019 16.3 we have been adding features to improve build parallelism. These features are still experimental, so they are off by default. When developing tools for Android, we introduced clang\/gcc to the MSBuild platform. Clang\/gcc relied on the parallelism model of the build system but MSBuild only parallelizes at the project level. This led to the creation of Multi-ToolTask (MTT) as a MSBuild Task. It forgoes MSBuild batching system and works around the typical single task limitations. This allows tasks to execution in parallel and engage other scheduling features not present in MSBuild. In this release, we leveraging MTT to the some of the existing Vcxproj build tasks, making existing tasks more parallel and in return improving build throughput.<\/p>\n<h3>Getting Started<\/h3>\n<p>MTT can be \u201copt-in\u201d by setting the MSBuild property or environment variable <em>UseMultiToolTask<\/em> to true. Its usage should be transparent during day-to-day-developer workflow and it fully supports incremental builds in the IDE and on the command line, even when toggling MTT on and off. To set properties, you can set them as environment variables or follow the instructions in <a href=\"https:\/\/docs.microsoft.com\/en-us\/visualstudio\/msbuild\/customize-your-build?view=vs-2019\">Customize your build<\/a>. For the best effect, apply these properties to all projects within a solution.<\/p>\n<h3>Why Use MTT?<\/h3>\n<p>When enabled, the MTT uses its built-in scheduler, which enables some features to control its throughput. By setting property <em>EnforceProcessCountAcrossBuilds<\/em> to true, this will limit the max number of process used by MTT across multiple projects and MSBuild instances. This feature should help to combat slowdown and memory bounds brought on by over-subscription. For extra control, use the <em>MultiProcMaxCount<\/em> or <em>CL_MPCount<\/em> properties to define the max number of jobs. <em>CL_MPCount<\/em> property is set by the IDE (Tools &gt; Options &gt; Projects and Solutions &gt; Maximum Concurrent C++ Compilations). By default, <em>MultiProcMaxCount<\/em> and <em>CL_MPCount<\/em> value are equal to the number of CPU logical processors.<\/p>\n<p>Lastly, setting the metadata <em>MultiToolTaskDependency<\/em> on an item will create a dependency on another item in the same MTT instance. For example, in our project system, we build .cpp source files to generate PCH first and then build their consumer. In MTT, it is possible to describe this dependency and the scheduler will handle the order. With the dependency description, it allows .cpp without dependency on the PCH to run without waiting, opening more parallelism opportunities.<\/p>\n<p>Performance gains will vary between sources base. Kevin wrote this blog to <a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/introducing-c-build-insights\/\">use xperf to measure your performence.<\/a>\u00a0 In this release, MTT is only coded to parallelize MIDL, CL, Clang, and FXC (hlsl).\u00a0 If your project is using Custom Build Tools, then enable <a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/parallel-custom-build-tools-in-visual-studio-2017\/\">Parallel Custom Build Tools<\/a> with a few clicks.\u00a0 If there are other tools that you think could benefit, send us feedback.<\/p>\n<h3 class=\"\">Send Us Feedback<\/h3>\n<p>The feature is still experimental, and so we are still looking for ways to improve it. Tell us what your experience was or suggest ways to improve the system. Our focus is correctness, incrementality, and scalability. Leave your comments below or email us visualcpp@microsoft.com.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Starting in Visual Studio 2019 16.3, we have been adding features to improve build parallelism.<\/p>\n","protected":false},"author":16383,"featured_media":35994,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[270],"tags":[],"class_list":["post-25393","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-announcement"],"acf":[],"blog_post_summary":"<p>Starting in Visual Studio 2019 16.3, we have been adding features to improve build parallelism.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/25393","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/users\/16383"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/comments?post=25393"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/25393\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media\/35994"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media?parent=25393"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/categories?post=25393"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/tags?post=25393"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}