blitz-research / monkey

Blitz Research Monkey Source
225 stars 59 forks source link

Optimised GetDecl process for faster semanting across multiple files #86

Open JocelynSachs opened 8 years ago

JocelynSachs commented 8 years ago

I discovered a significant speed-bump in the semanting process: every time a declaration made in file A is used in file B, the compiler rebuilds the entire import hierarchy of file B from scratch and searches every declaration map individually for conflicts.

In practice, this resulted in a near-linear relationship between number of files and semanting time for any given quantity of code.

This modified implementation improves performance by constructing the import hierarchy of file B just once, the first time a declaration is sought outside the file. From this it caches a single map of synonyms (lists of decls with the same identifier).

Subsequently, seeking an external decl requires only a single string map lookup to obtain the appropriate synonym list. In correct code, only one synonym will pass the final accessibility test. If more than one pass, a duplicate identifier error is reported (via the old method, both for simplicity and to sanity-check the behaviour of the new system)

The upshot is a considerable reduction in semanting time on projects with large numbers of source files (from 45 seconds to under 3 seconds in our case).