BetterReflection icon indicating copy to clipboard operation
BetterReflection copied to clipboard

Adding methods for sequential processing and filtering of class reflections

Open shcherbanich opened this issue 10 months ago • 3 comments

I made a small optimization of the FileIteratorSourceLocator so that all files are not loaded into the array before filtering, but only after it, and also added new functionality for sequential work with files and the ability to filter them.

Motivation

When working with really big projects, performance issues often arise. They can be solved with some techniques, such as sequential file processing. This was my main motivation for this work.

What has been done?

  1. New methods for sequentially obtaining *Reflection have been added to SourceLocators;
  2. A wrapper method has been added to DefaultReflector for sequentially obtaining reflect classes;
  3. A filtering system has been implemented for obtained *Reflection. In most cases, filters are triggered before all complex operations with AST, so filtering in this way is a much more productive method than obtaining individual classes using reflectClass;
  4. The method for processing files in FileIteratorSourceLocator has been changed. Now they are processed sequentially, and not immediately loaded into an array. This reduces resource consumption and speeds up the work of this locator.

shcherbanich avatar Jan 04 '25 20:01 shcherbanich

Related: https://github.com/Roave/BetterReflection/issues/614

Ocramius avatar Jan 05 '25 04:01 Ocramius

@Ocramius , thank you for the review!

I agree that the changes turned out to be too big. In this case, I suggest splitting this work into 3 separate parts with 3 separate PRs:

  1. Changing the default behavior of reflectAllClasses / reflectAllFunctions / reflectAllConstants in DefaultReflector and using the generator as the default solution in source locators;

  2. Implementing filtering using a new source locator (I'll think about how to do it better);

  3. Optimizing SingleFileSourceLocator (I'll try to remake it in the form you noted in the comments).

I'll start doing this in the specified order if you don't mind :)

UPD: first part completed here: https://github.com/Roave/BetterReflection/pull/1476

shcherbanich avatar Jan 05 '25 09:01 shcherbanich

When working with really big projects, performance issues often arise. They can be solved with some techniques, such as sequential file processing. This was my main motivation for this work.

would be great to have some kind of benchmark to compare the performance before/after this PR

staabm avatar Jan 06 '25 17:01 staabm