Index: msvc.jam
===================================================================
--- msvc.jam	(revision 86722)
+++ msvc.jam	(working copy)
@@ -32,6 +32,7 @@
 import pch ;
 import property ;
 import rc ;
+import set ;
 import toolset ;
 import type ;
 
@@ -677,6 +678,22 @@
 }
 
 
+# Helper rule to get the environment side-effects of a batch file.
+# We used to call MSVC setup scripts directly in every action, however in
+# newer MSVC versions (10.0+) they make long-lasting registry queries 
+# which have a significant impact on build time.
+# Note that this requires 'cmd.exe' based SHELL, it will not work with
+# Cygwin built b2.
+local rule batch-file-environment ( batch-file )
+{
+    local original-vars = [ SPLIT_BY_CHARACTERS [ SHELL set ] : "\n" ] ;
+    local new-vars = [ SPLIT_BY_CHARACTERS [ SHELL "$(batch-file)>nul && set" ] : "\n" ] ;
+    local diff-vars = [ set.difference $(new-vars) : $(original-vars) ] ;
+    diff-vars = "SET "$(diff-vars) ;
+    return $(diff-vars:J="\n")\n ;
+}
+
+
 # Worker rule for toolset version configuration. Takes an explicit version id or
 # nothing in case it should configure the default toolset version (the first
 # registered one or a new 'default' one in case no toolset versions have been
@@ -887,14 +904,6 @@
                 default-global-setup-options-ia64 = ia64 ;
             }
 
-            local setup-prefix = "call " ;
-            local setup-suffix = " >nul"$(.nl) ;
-            if ! [ os.name ] in NT
-            {
-                setup-prefix = "cmd.exe /S /C call " ;
-                setup-suffix = " \">nul\" \"&&\" " ;
-            }
-
             for local c in $(cpu)
             {
                 local setup-options ;
@@ -927,7 +936,8 @@
                 # Append setup options to the setup name and add the final setup
                 # prefix & suffix.
                 setup-options ?= "" ;
-                setup-$(c) = $(setup-prefix)$(setup-$(c):J=" ")" "$(setup-options:J=" ")$(setup-suffix) ;
+
+                setup-$(c) = $(setup-$(c):J=" ") $(setup-options:J=" ") ;
             }
         }
 
@@ -981,6 +991,20 @@
             local cpu-assembler = $(assembler) ;
             cpu-assembler ?= $(default-assembler-$(c)) ;
 
+            if $(setup-$(c))
+            {
+                if ! [ os.name ] in NT
+                {
+                    local prefix = "cmd.exe /S /C call " ;
+                    local suffix = " \">nul\" \"&&\" " ;
+                    setup-$(c) = $(prefix)$(setup-$(c):J=" ")$(suffix) ;
+                }
+                else
+                {
+                    setup-$(c) = [ batch-file-environment $(setup-$(c):J=" ") ] ;
+                }
+            }
+
             toolset.flags msvc.compile .CC  $(cpu-conditions) : $(setup-$(c))$(compiler) /Zm800 -nologo ;
             toolset.flags msvc.compile .RC  $(cpu-conditions) : $(setup-$(c))$(resource-compiler) ;
             toolset.flags msvc.compile .ASM $(cpu-conditions) : $(setup-$(c))$(cpu-assembler) -nologo ;
