Skip to content

PythonEngine.Initialize slow #598

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
goerch opened this issue Jan 14, 2018 · 5 comments
Closed

PythonEngine.Initialize slow #598

goerch opened this issue Jan 14, 2018 · 5 comments

Comments

@goerch
Copy link

goerch commented Jan 14, 2018

Environment

  • Pythonnet version: 2.3.0
  • Python version: 3.6
  • Operating System: Windows 7

Details

When embedding Python in an ASP.NET MVC 5 web application, PythonEngine.Initialize needs a couple of seconds to eagerly load the names of around 50 module namespaces in ModuleObject.LoadNames. If I replace the implementation of LoadNames with a NOP, time spent in PythonEngine.Initialize drops to below 100 ms and the web application still seems to work.

@dmitriyse
Copy link
Contributor

We already have PR for that problem. See #528

Also try to build python.net from the branch https://github.com/pythonnet/pythonnet/tree/featured
This branch contains muptiple not yet merged fixes to the master branch.

@goerch
Copy link
Author

goerch commented Jan 15, 2018

I don't fully understand the idea of eager initialization of the cache in ModuleObject.LoadNames when other members of ModuleObject use lazy caching. At least in my use case (using only a couple of methods of the 50+ module namespaces) this seems to be a bad tradeoff.

Are there any benchmarks to justify this design?

@goerch
Copy link
Author

goerch commented Jan 15, 2018

Just tested the branch https://github.com/pythonnet/pythonnet/tree/featured. Response time is down to 200 ms with eager initialization of 50+ module namespaces. Thanks for your help!

@goerch goerch closed this as completed Jan 15, 2018
@pierce-martin
Copy link

pierce-martin commented Apr 25, 2018

@dmitriyse When will this fix be incorporated into a release? The branch https://github.com/pythonnet/pythonnet/tree/featured seems to work great, but it doesn't appear that master has these changes. Thanks.

@den-run-ai
Copy link
Contributor

this is now in master branch: #723

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants