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

Only reload cache once for rope_autoimport #463

Conversation

tkrabel-db
Copy link
Contributor

Addressed #461 (comment) and a minor bug.

Comment on lines +255 to +258
if config.plugin_settings("rope_autoimport").get("enabled", False) and not ENABLED:
_reload_cache(config, workspace)
else:
log.debug("autoimport: Skipping cache reload.")
Copy link
Contributor

@rchl rchl Oct 16, 2023

Choose a reason for hiding this comment

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

In a situation when it's disabled and then re-enabled again later we should reload the cache. So we should change ENABLED to false in the else case.

BTW. I wasn't aware before that _reload_cache is called quite often (on file open and save). Knowing that, I suppose this is not really that much of a performance issue really... Sorry for not checking it properly before

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, I checked it myself and this indeed can be a performance issue. On a larger python venv with all the latest data science packages like pandas, sklearn and the sort, we have ~130 python packages in that venv, which takes 30sec for rope to scan if memory = True. That said, I see future work to make _reload_cache async, so that the language server is unblocked and can handle other requests while loading the cache.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm, thinking about this more, I start doubting the value of this PR. workspace/didChangeConfiguration is something I expect a user to set once during the session, not so often that it's worth adding a state machine to rope_autoimport now. And the inefficiencies won't be an issue anyway when rope is disabled. Also, when rope creates an index DB, reloading the cache is fast (~1 sec on 130 dependencies).
On the other hand, the state machine added would get fairly complicated, making it harder to reason about the logic, and as code is more often read than written, I'm hesitant to add it just now. Let's wait for user feedback first.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That said, I open a separate PR to fix the obvious bug in the code.

Copy link
Contributor

Choose a reason for hiding this comment

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

I expect a user to set once during the session, not so often that it's worth adding a state machine to rope_autoimport now

It would be buggy without it. The user would disable cache and on enabling it later the cache would be stale.

Maybe a corner case but it would still result in incorrect behavior so I think we shouldn't ignore it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, sorry, you meant it's an option to drop this whole PR rather than not addressing my comment. Yeah, that's probably fine too given how often the cache is reloaded anyway.

Copy link
Member

Choose a reason for hiding this comment

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

workspace/didChangeConfiguration is something I expect a user to set once during the session, not so often that it's worth adding a state machine to rope_autoimport now

Actuallly, this can happen several times in a single session (at least in Spyder) because users can enable/disable pycodestyle, pydocstyle or change their preferred auto-formatter provider in Spyder Preferences. And all that involves a didChangeConfiguration.

Hm, thinking about this more, I start doubting the value of this PR.
Also, when rope creates an index DB, reloading the cache is fast (~1 sec on 130 dependencies).

Ok, so do you prefer to close this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, let's close this

@ccordoba12 ccordoba12 changed the title rope_autoimport - only reload cache once Only reload cache once for rope_autoimport Oct 16, 2023
@ccordoba12 ccordoba12 added this to the v1.9.0 milestone Oct 16, 2023
@ccordoba12 ccordoba12 added the enhancement New feature or request label Oct 16, 2023
@ccordoba12 ccordoba12 removed this from the v1.9.0 milestone Oct 19, 2023
@ccordoba12 ccordoba12 closed this Oct 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants