google / tern-closure

A Tern plugin adding Closure support.
Apache License 2.0
32 stars 18 forks source link

Minimal requirements loading #22

Closed jgiles closed 10 years ago

jgiles commented 10 years ago

Currently, we try to load files for all the referenced types in all the files we process, including those that we are loading automatically from other files. This means that for anything other than smallish projects, we just keep loading files until Tern's dependency budget system cuts us off.

This is a problem because many of the loaded files are not actually necessary for understanding the current file. By loading unnecessary files, we are bloating memory consumption and slowing things down. We could even end up consuming the dependency budget on unneeded files and preventing the processing of something that actually matters.

It seems like we should only need to load:

  1. goog.require classes in the current file.
  2. Types referenced in type annotations in the current file.
  3. Any types we could obtain from the above types (return types of their methods).
    • Recurse.
  4. Superclasses of all of the above.
    • Recurse
jgiles commented 10 years ago

It's a little more complicated than this. Something annotated with @type can be a field visible to other files, and an @param annotation in an interface or superclass is relevant to implementors and subclasses. Without considering the relationships between files, it seems we can eliminate types in @private annotations but not much else.