monkey icon indicating copy to clipboard operation
monkey copied to clipboard

Optimised GetDecl process for faster semanting across multiple files

Open JocelynSachs opened this issue 9 years ago • 0 comments

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).

JocelynSachs avatar Nov 03 '15 12:11 JocelynSachs