3

I have since long suffered from long startup times when building with SCons. On my old work laptop, it could take up to 60 seconds to just build the most fundamental hello world-example.

I just received a new laptop, so I had the opportunity to investigate this further. Our laptops come preloaded with Visual Studio 2010 and some other stuff. I also need Visual Studio 2015.

On the newly unpacked PC, a build of hello world took "only" 10 seconds (python 2.7.14, scons 3.0.0, no other major applications running)

After installing VS2015, the time went up to 20 seconds.

I can compare this with my 10 year old PC at home, where the same build takes less than 2 seconds (however, only VS2015 there).

What could be the reason for this extreme slowness? Can something be done? It seems like execution of the vcvars scripts and so are responsible. But why so slow on my work computers and not at home? How can I troubleshoot this further?

   Ordered by: cumulative time
   List reduced from 1104 to 20 due to restriction <20>

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.000    0.000   20.500   20.500 C:\Python27\scons-3.0.0\SCons\Script\Main.py:831(_main)
        1    0.000    0.000   20.324   20.324 C:\Python27\scons-3.0.0\SCons\Script\SConscript.py:155(_SConscript)
        1    0.000    0.000   20.323   20.323 C:\Temp\SConstruct:1(<module>)
      3/2    0.000    0.000   20.321   10.161 C:\Python27\scons-3.0.0\SCons\Environment.py:897(__init__)
      3/2    0.000    0.000   20.314   10.157 C:\Python27\scons-3.0.0\SCons\Environment.py:93(apply_tools)
        2    0.000    0.000   20.314   10.157 C:\Python27\scons-3.0.0\SCons\Environment.py:1782(Tool)
     28/2    0.000    0.000   20.313   10.157 C:\Python27\scons-3.0.0\SCons\Tool\__init__.py:271(__call__)
        2    0.000    0.000   20.313   10.157 C:\Python27\scons-3.0.0\SCons\Tool\default.py:38(generate)
        2    0.000    0.000   20.150   10.075 C:\Python27\scons-3.0.0\SCons\Tool\mslink.py:256(generate)
        8    0.000    0.000   20.150    2.519 C:\Python27\scons-3.0.0\SCons\Tool\MSCommon\vc.py:432(msvc_setup_env_once)
        2    0.000    0.000   20.150   10.075 C:\Python27\scons-3.0.0\SCons\Tool\MSCommon\vc.py:531(msvc_setup_env)
        2    0.000    0.000   20.149   10.074 C:\Python27\scons-3.0.0\SCons\Tool\MSCommon\vc.py:442(msvc_find_valid_batch_script)
        2    0.000    0.000   20.148   10.074 C:\Python27\scons-3.0.0\SCons\Tool\MSCommon\vc.py:381(script_env)
        1    0.000    0.000   20.147   20.147 C:\Python27\scons-3.0.0\SCons\Tool\MSCommon\common.py:144(get_output)
       12   20.134    1.678   20.134    1.678 {method 'read' of 'file' objects}
        1    0.000    0.000    0.173    0.173 C:\Python27\scons-3.0.0\SCons\Script\Main.py:1109(_build_targets)
        1    0.000    0.000    0.172    0.172 C:\Python27\scons-3.0.0\SCons\Job.py:100(run)
        1    0.000    0.000    0.169    0.169 C:\Python27\scons-3.0.0\SCons\Job.py:186(start)
        3    0.000    0.000    0.156    0.052 C:\Python27\scons-3.0.0\SCons\Action.py:644(__call__)
        2    0.000    0.000    0.155    0.078 C:\Python27\scons-3.0.0\SCons\Script\Main.py:184(execute)

My SConstruct file:

env = Environment()
hello = Program(["hello.c"])
matli
  • 27,922
  • 6
  • 37
  • 37
  • What happens if you add "DefaultEnvironment(tools=[])" – bdbaddog Apr 25 '18 at 23:50
  • @bdbaddog It takes the same amount of time, but fails to build due to `'SConsEnvironment' object has no attribute 'Program'` – matli Apr 26 '18 at 09:54
  • Add env.Program() instead of Program() – bdbaddog Apr 27 '18 at 00:42
  • Also Environment(tools=['msvc','mslink']) should be sufficient – bdbaddog Apr 27 '18 at 00:43
  • @bdbaddog, those suggestions seems to make no significant difference. – matli Apr 27 '18 at 06:54
  • My first guess would be that you have some (or even many) network drives in your `$PATH`. So a lot of stuff has to get searched at rather slow pace for finding out which tools exist in the current system... – dirkbaechle Apr 27 '18 at 09:02
  • @dirkbaechle That's a good guess. Unfortunately, this is not the case though. – matli Apr 27 '18 at 11:02
  • Can you please run `scons` with the `--debug=time` option and publish the results here? Maybe we can see in which section of the build all the time gets spent. – dirkbaechle Apr 27 '18 at 12:04
  • set SCONS_MSCOMMON_DEBUG=%TEMP%\scons_msdebug.log run your scons, and pastebin the output in scons_msdebug.log – bdbaddog Apr 27 '18 at 19:00
  • @bdbaddog Here is the pastebin: https://pastebin.com/5Qnv0rqf – matli Apr 29 '18 at 21:29
  • @dirkbaechle Basically everything is spent in "Total SConscript file execution time" (21.621 seconds out of 21.737) – matli Apr 29 '18 at 21:29
  • Try adding Environment(tools=['msvc','mslink'], MSVC_VERSION="14.0"), and pastebin the output as before (with the SCONS_MSCOMMON_DEBUG). You have 4 versions of MSVC installed and it may be using time looking at each version. (From your provided log "DEBUG:root:installed_vcs:['14.0', '12.0', '11.0', '10.0']") – bdbaddog Apr 29 '18 at 21:52
  • @bdbaddog New paste: https://pastebin.com/NGBpsJ6V (The execution time is still approximately the same, around 20 s) – matli Apr 29 '18 at 22:26
  • Is your "sandbox" on a network mounted drive? – bdbaddog Apr 30 '18 at 23:44
  • Do you have a site_init/site_scons ? Similar to above took 5 seconds on my computer. (i5-3570 3.4Ghz, Win 10 Pro, py 2.7.14, VS 2017) – bdbaddog Apr 30 '18 at 23:52
  • With DefaultEnvironment(tools=[]), and Environment(tools=['msvc','mslink']), it took 3.84 seconds. – bdbaddog Apr 30 '18 at 23:54
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/170117/discussion-between-bdbaddog-and-matli). – bdbaddog May 01 '18 at 00:04

1 Answers1

2

The solution here, according to the chat, was to disable the Antivirus software running on the machine.

With this, the SCons startup time went from 40 to 2 seconds. Also significant performance improvement in other areas could be noticed.

dirkbaechle
  • 3,984
  • 14
  • 17
  • I wonder if there's not a way to whitelist scons's activities in this case and avoid totally disabling the antivirus.. – bdbaddog Jul 20 '18 at 16:19
  • We tried finding a way to whitelist relevant activities, but couldn't really find a good way to isolate them. However, we did not have to disable all antivirus software, only the HIPS part (of Eset Nod32). Unfortunately, I still have some issues, but I finally gave up due to lack of time. My current workaround is to use an older SCons version, which does not recognise VS2015 and therefore performs a lot less registry lookups at startup. – matli Jul 21 '18 at 13:00