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 reindex documents if declarations are being modified #2942

Open
wants to merge 1 commit into
base: 11-29-index_documents_on_modification
Choose a base branch
from

Conversation

vinistock
Copy link
Member

@vinistock vinistock commented Nov 29, 2024

Motivation

This PR tries to limit the amount of times we pay the price of reindexing the current document being modified by analyzing the context behind the last edit made to it.

Implementation

The idea of this approach is to remember the position of the last edit made to a document and the nature of the edit (insert, replace or delete).

Then, depending on the type of edit and what nodes exist under the position where the edit was made, we decide if reindexing is relevant or not.

To determine that, we look at the node under the cursor and, if it matches a node we use for indexing in the DeclarationListener, then we consider that we need to reindex.

It's not perfect, so let me know if you have other ideas on how to determine this in a way that is:

  1. Fast
  2. Accurate

Necessarily in this order because the whole point is to reduce the performance impact of having to reindex. If detecting whether we need to do it or not is equally as slow, then there's no point in doing it.

Automated Tests

Added some tests, but we should probably add more.

Copy link
Member Author

vinistock commented Nov 29, 2024

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@vinistock vinistock added enhancement New feature or request server This pull request should be included in the server gem's release notes labels Nov 29, 2024 — with Graphite App
@vinistock vinistock marked this pull request as ready for review November 29, 2024 21:41
@vinistock vinistock requested a review from a team as a code owner November 29, 2024 21:41
@@ -64,7 +64,6 @@ def initialize(index, dispatcher, parse_result, uri, collect_comments: false)
:on_constant_path_or_write_node_enter,
:on_constant_path_operator_write_node_enter,
:on_constant_path_and_write_node_enter,
:on_constant_or_write_node_enter,
Copy link
Member Author

Choose a reason for hiding this comment

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

This event was duplicated.

Copy link
Contributor

Choose a reason for hiding this comment

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

Should we change Prism detect this and emit an error/warning?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'd rather make our cop smarter if we can avoid paying the price on every single listener instantiation.

@vinistock vinistock force-pushed the 11-29-index_documents_on_modification branch from 41cc250 to 826bd1a Compare November 29, 2024 21:51
@vinistock vinistock force-pushed the 11-29-only_reindex_documents_if_declarations_are_being_modified branch 2 times, most recently from c103d7c to ea92bc7 Compare November 29, 2024 21:59
@@ -64,7 +64,6 @@ def initialize(index, dispatcher, parse_result, uri, collect_comments: false)
:on_constant_path_or_write_node_enter,
:on_constant_path_operator_write_node_enter,
:on_constant_path_and_write_node_enter,
:on_constant_or_write_node_enter,
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we change Prism detect this and emit an error/warning?

lib/ruby_lsp/ruby_document.rb Outdated Show resolved Hide resolved
@vinistock vinistock force-pushed the 11-29-index_documents_on_modification branch from 826bd1a to 2251c9d Compare December 10, 2024 16:06
@vinistock vinistock force-pushed the 11-29-index_documents_on_modification branch from 2251c9d to e5b8c20 Compare December 10, 2024 19:55
@vinistock vinistock force-pushed the 11-29-only_reindex_documents_if_declarations_are_being_modified branch from ea92bc7 to f299a65 Compare December 10, 2024 19:55
@vinistock vinistock requested a review from andyw8 December 10, 2024 19:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request server This pull request should be included in the server gem's release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants