Skip to content
This repository has been archived by the owner on Nov 4, 2023. It is now read-only.

Optimised GetDecl process for faster semanting across multiple files #86

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from

Conversation

JocelynSachs
Copy link

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

Added caching of indirectly accessible decls to speed up semanting on projects with large numbers of files.
Used by optimised ModuleDecl.GetDecl.
Optimised ModuleDecl.GetDecl
ALL caches are now dirtied when a module has decls added (since those caches could contain indirect references that are now out of date.
Thanks Anthony for the heads up.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants