Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid O(N^2) scan through globals during name resolution #5001

Open
michaeljklein opened this issue May 8, 2024 · 0 comments
Open

Avoid O(N^2) scan through globals during name resolution #5001

michaeljklein opened this issue May 8, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@michaeljklein
Copy link
Contributor

Problem

the following code
in the resolver scans through all previous global's whenever a global is added, resulting in O(num_globals^2):

        // This check is necessary to maintain the same definition ids in the interner. Currently, each function uses a new resolver that has its own ScopeForest and thus global scope.
        // We must first check whether an existing definition ID has been inserted as otherwise there will be multiple definitions for the same global statement.
        // This leads to an error in evaluation where the wrong definition ID is selected when evaluating a statement using the global. The check below prevents this error.
        let mut global_id = None;
        let global = self.interner.get_all_globals();
        for global_info in global {
            if global_info.ident == name
                && global_info.local_id == self.path_resolver.local_module_id()
            {
                global_id = Some(global_info.id);
            }
        }

Happy Case

Store global variables in a set or (hash)map to allow looking them up quickly

Project Impact

Nice-to-have

Impact Context

No response

Workaround

None

Workaround Description

No response

Additional Context

No response

Would you like to submit a PR for this Issue?

None

Support Needs

No response

@michaeljklein michaeljklein added the enhancement New feature or request label May 8, 2024
@jfecher jfecher changed the title Avoid O(N^2) scan through generics Avoid O(N^2) scan through globals during name resolution May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: 📋 Backlog
Development

No branches or pull requests

1 participant