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

refactor: change the way of checking variable has been declared #897

Merged
merged 1 commit into from
Jan 29, 2024

Conversation

zhangpanweb
Copy link
Contributor

@zhangpanweb zhangpanweb commented Jan 27, 2024

写了一个对比的 visitor,让所有的 module 都跑 这个 visitorvisitor有两个版本,一个用 collect_decls,一个用 unresolved_mark 判定。用 normal的 example 来跑 puffin(yuyanAssets 跑了会栈溢出, examples/normal 已能看出差异) 。如下

collect_decls版本:

struct DiffCollectDecls {
    bindings: Lrc<AHashSet<Id>>,
}

impl VisitMut for DiffCollectDecls {
    fn visit_mut_module(&mut self, module: &mut Module) {
        mako_profile_scope!("node_stuff_visit_module");

        self.bindings = Lrc::new(collect_decls(&*module));
        module.visit_mut_children_with(self);
    }
}

puffin stat 如下
image

unresolved_mark版本

struct DiffCollectDecls {
    unresolved_mark: Mark,
}

impl VisitMut for DiffCollectDecls {
    fn visit_mut_module(&mut self, module: &mut Module) {
        mako_profile_scope!("node_stuff_visit_module");

        if module.span.ctxt.outer() == self.unresolved_mark {}
        module.visit_mut_children_with(self);
    }
}

puffin stat 如下
image

结论:unresolved_mark 有明显优势 ,pr 把代码中通过 collect_decls bindings 的判定方式都改为使用unresolved_mark的方式

@sorrycc sorrycc merged commit 3d573b6 into master Jan 29, 2024
8 checks passed
@delete-merged-branch delete-merged-branch bot deleted the refactor/var-declared-check branch January 29, 2024 03:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants