This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Delay-load ShellExecute
Type: enhancement Stage: resolved
Components: Windows Versions: Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: steve.dower Nosy List: brett.cannon, python-dev, steve.dower, tim.golden, zach.ware
Priority: normal Keywords: patch

Created on 2015-01-16 23:11 by steve.dower, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
23253.diff steve.dower, 2015-01-17 18:00 review
Messages (7)
msg234151 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2015-01-16 23:11
Currently, pythonXY.dll has a dependency on shell32.dll solely for the os.startfile (Modules/posixmodule.c) function. This is quite a heavy dependency that many would rather not have to load (e.g. lightweight server configurations).

It would be nice to delay load the DLL and fail the operation if it is not available.

(This is as much a reminder for myself as anything else, but if someone wants to do it then feel free.)
msg234183 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2015-01-17 18:00
Attached a patch.

Comparing the time for "python.exe -c '0'" with Powershell's Measure-Command tool, it looks like there's a 3-4ms (~8-10%) improvement in startup time too. That's not at all robust, but it's certainly no worse. (I'm not surprised - shell32.dll is a horrendously big dependency and we're better off without it.)
msg234199 - (view) Author: Tim Golden (tim.golden) * (Python committer) Date: 2015-01-17 21:21
I'm +0.75. I think the idea's fine in principle and the patch (by 
inspection) seems to do the right things.

My only concerns are: that posixmodule.c becomes even longer and more 
involved; and that the benefit might not quite be great enough to 
justify the added complexity.
msg234201 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2015-01-17 22:00
Yeah, I hate touching posixmodule.c for the same reason. It'd be nice to split it up into separate platform files, but nobody is volunteering for that.

If you focus on the performance, then yeah, this change probably isn't worth it. OTOH, the number of Windows platforms keep increasing (e.g. ARM, phone/tablet/various sandboxes, etc.) and the fewer dependencies we have the more likely Python will Just Work in them. (And the more value that a split up posixmodule.c will have... guess it'll have to happen eventually.)
msg234255 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2015-01-18 16:06
If you want a robust measurement of startup impact, the benchmark suite has two benchmarks specifically for startup (w/ and w/o site.py).
msg234621 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2015-01-24 16:49
I assume you're referring to normal_startup and startup_nosite in perf.py at h.p.o/benchmarks? Handy to know about (I need to explore our top-level repos more often, obviously), but probably still not going to measure time in the Windows PE loader as accurately as it'd need to be to conclusively prove a speed advantage. I'd probably need to hit up the Windows team for some of their profiling tools to get good numbers here.

Still, it's indisputable that this change will reduce the initial memory overhead, so I'll take Tim's 0.75 and run with it :)
msg234622 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-01-24 16:54
New changeset 5bff604a864e by Steve Dower in branch 'default':
Closes #23253: Delay-load ShellExecute
https://hg.python.org/cpython/rev/5bff604a864e
History
Date User Action Args
2022-04-11 14:58:11adminsetgithub: 67442
2015-01-24 16:54:29python-devsetstatus: open -> closed

nosy: + python-dev
messages: + msg234622

resolution: fixed
stage: patch review -> resolved
2015-01-24 16:49:22steve.dowersetmessages: + msg234621
2015-01-18 16:06:18brett.cannonsetmessages: + msg234255
2015-01-18 16:05:27brett.cannonsetnosy: + brett.cannon
2015-01-17 22:00:06steve.dowersetmessages: + msg234201
2015-01-17 21:21:03tim.goldensetmessages: + msg234199
title: Delay-load ShellExecute[AW] in os.startfile -> Delay-load ShellExecute
2015-01-17 18:00:33steve.dowersetassignee: steve.dower
stage: patch review
2015-01-17 18:00:14steve.dowersetfiles: + 23253.diff
keywords: + patch
messages: + msg234183
2015-01-16 23:11:50steve.dowercreate