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

IndexedReferenceFinder: possibly too wide scope of searching #2644

Open
przepompownia opened this issue Apr 21, 2024 · 11 comments
Open

IndexedReferenceFinder: possibly too wide scope of searching #2644

przepompownia opened this issue Apr 21, 2024 · 11 comments

Comments

@przepompownia
Copy link
Contributor

przepompownia commented Apr 21, 2024

For example, go to lib/CodeTransform/Adapter/WorseReflection/Transformer/ImplementContracts.php and find references to $reflector private property.

Currently as a user I get notifications about scanning ~300 references
image

I started to debug what happens. At the moment I see that:

  1. $reflector is detected as a variable, not a property. It probably needs some fixing.
  2. Even assuming that we search for references to a variable I need an explanation why searching is performed outside the class. Not sure if it's worth attention after fixing 1.
@mamazu
Copy link
Contributor

mamazu commented Apr 21, 2024

I mean for properties it also would make sense to take the visibility into account. Like searching for a private variable outside of the class makes no sense and searching for protected variables outside of the inheritance hierarchy makes no sense as well.

@przepompownia
Copy link
Contributor Author

przepompownia commented Apr 21, 2024

For the record: in class X { function __construct(public $<>y) { print($y); } } $y needs to be considered both property and variable.

@mamazu
Copy link
Contributor

mamazu commented Apr 21, 2024

Yeah, but both should have a very limited scope. The variable only in the constructor and the member only in this class.

@dantleech
Copy link
Collaborator

dantleech commented Apr 21, 2024

Fwiw the legacy reference finder does take visibility into account and is obviously many times faster for private and protected members, it' a missing feature in the "new" system

@przepompownia
Copy link
Contributor Author

przepompownia commented Apr 21, 2024

At the moment I give up. I found that we search for property type (as expected) in MemberQuery

image

but have not idea when and how the list of references should be restricted accordingly to the visibility.

@mamazu
Copy link
Contributor

mamazu commented Apr 22, 2024

Okay, I think that might be an indexer problem, it's looking through all references of all files. Which for the $reflector is 218 file references. So renaming the reference to $reflector1 would improve the reference finder.

@mamazu
Copy link
Contributor

mamazu commented May 19, 2024

@dantleech I have a question because it sounds so obvious:

  • When indexing a member we only index (for reference finding) the references with file and offset
  • When finding references: we open the file reflect on it and check if the class is in the class hierarchy of our class.

Why don't we also index the context of the reference (for example the class name) into the record? Yes this increases the size of the index but it will drastically reduce the amount of work reference finding takes.

@dantleech
Copy link
Collaborator

Yes this increases the size of the index but it will drastically reduce the amount of work reference finding takes

AFAIK we do index the class name (the MemberRecord::$containerType) but we cannot do this when it's not known at compile time. statically analysing the code when creating the index would make the indexing process 1000s of times slower (not to mention that the index can often be inaccurate for various reasons).

@dantleech
Copy link
Collaborator

have not idea when and how the list of references should be restricted accordingly to the visibility.

basically you don't need the indexer here, you only need reflection. so refactoring is probably required.

@mamazu
Copy link
Contributor

mamazu commented Jun 9, 2024

AFAIK we do index the class name (the MemberRecord::$containerType) but we cannot do this when it's not known at compile time.

I think I'm starting to understand the problem now and I completely agree that static analysis on indexing is a bad idea but maybe we could add a best guess, like if you're accessing $this->prop on class A, then the container type of prop could be A. (It's not perfect in case of inheritance) but it will definitely reduce the amount of results quicker.

@dantleech
Copy link
Collaborator

dantleech commented Jun 9, 2024

For private and protected the speed can be i increased significantly by not using the indexer at all... which is exactly what the non LSP version does (and it's reliable as doesn't depend on thrnindex to work)

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

3 participants