In drupal we have several ways to collect metadata. We mostly use hooks. When using hooks the metadata and the actual code that uses the data are seperated. To improve dx we would like to capture the metadata inside the code that needs it.
In the current testing system we use a getInfo() function inside each class to collect the data. The problem with this approach is that we need to put every test file into memory. For tests this is/was acceptable because developer environments where tests are typically run are much less memory constrained than live sites.
For plugins we also need such a discovery mechanism. And yes we don't want to use hooks :)
But we can't use the
getInfo() method because it would require loading every class in memory and so affect our memory consumption too much. Also it would make documentation much harder as it would require parsing PHP code to get it out.
Use the doctrine annotation mechanism to fetch the data. In Doctrine 2.2 it had the same problems as the getInfo() approach, it had to load every single file into memory. It's likely that Drupal will contain lots of plugins so memory usage would be sky high .
Chx made a patch for doctrine 2.3 that uses the php tokenizer. This approach consumes more cpu but it's memory usage isn't related to the number of plugins. Instead it has a peak memory related to the filesize. As Psr0 contains lots of small files with only a single class in it this shouldn't be a problem. Chx thinks this should give an average memory peak of 700kb for each file.
With a annotation mechanism in place, some might put too much inside it. Thats why we should define properly what metadata can be defined with annotations.
A possible agreement: (merlinofchaos after a views irc discussion)
1) Metadata should be reserved for data that is used outside of the class instantiation.
2) Metadata that is used only after object instantiation should be moved to methods and/or protected variables that are accessed by said methods.
- The proposed restrictions above need to be documented somewhere.
- The plugin documentation should be updated to describe the use of annotations.
- There are a number of followup issues:
- A change notification should be added.
Annotations are available as a mechanism for plugin discovery (replacing info hooks).
Original report by EclipseGc
chx has done some very excellent work getting annotations+directory based discovery working. I wanted to expose this to the community at large, however this patch includes a bunch of symfony updates that were delivered through compiler. This issue is affecting me directly at the moment. Once that's committed this patch will get much saner.
I've provided a full patch and an interdiff against the plugins-next branch of http://drupal.org/sandbox/eclipsegc/1441840
The 8.x branch of http://drupal.org/sandbox/eclipsegc/1663586 should work with this patch now.
|PASSED: [[SimpleTest]]: [MySQL] 39,984 pass(es).|
|PASSED: [[SimpleTest]]: [MySQL] 39,980 pass(es).|
|PASSED: [[SimpleTest]]: [MySQL] 39,972 pass(es).|