Skip to content
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

Stop IPython from time consuming deep inspection of NodeCollection objects #3145

Merged
merged 2 commits into from
Mar 13, 2024

Conversation

heplesser
Copy link
Contributor

This solution fixes #3144 and was suggested by Harold Gutch via NEST User (12 March 2024) with the following explanation

What happens is that IPython's pretty printing calls (a bit down the line) the IPythonDisplayFormatter() class. The first thing that does is test if for the given object there is an _ipython_display_() method — if that exists, it calls that, otherwise it falls back to a more generic method. In your case the latter happens, it falls back to the more generic method and that is what then produces the output.

When looking up if there is an _iython_display_() method, the first thing IPython does is check for a method called _ipython_canary_method_should_not_exist_()— and it is precisely this lookup that takes so long. You can verify this by

getattr(n, "_ipython_canary_method_should_not_exist_")

which will also take rather long. As the output here also contains some SLI things, one might need to dig deeper to actually speed this up.

Instead, adding a check specifically for exactly the above mentioned lookup of _ipython_canary_method_should_not_exist_() also does the job ... . With that workaround, your example
returns instantaneously — as one would expect it to.

@heplesser heplesser added S: Normal Handle this with default priority T: Maintenance Work to keep up the quality of the code and documentation. I: No breaking change Previously written code will work as before, no one should note anything changing (aside the fix) labels Mar 12, 2024
Copy link
Contributor

@Helveg Helveg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a nitpick, fine either way :)

@terhorstd terhorstd changed the title Tell IPython to stop inspecting NodeCollection objects Stop IPython from time consuming deep inspection of NodeCollection objects Mar 13, 2024
@heplesser heplesser merged commit 7b9e2a4 into nest:master Mar 13, 2024
24 checks passed
@heplesser heplesser deleted the fix-slow-ipython branch April 24, 2024 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I: No breaking change Previously written code will work as before, no one should note anything changing (aside the fix) S: Normal Handle this with default priority T: Maintenance Work to keep up the quality of the code and documentation.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Displaying NodeCollection is very slow in IPython
3 participants