You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've observed that the current ecma_minifier implementation contains an excessive number of visitors, which introduces significant unnecessary overhead. My goal is to reduce this inefficiency.
There are two potential approaches:
Fundamental Solution: Create an IR that's both visitor-friendly and easily parallelizable. However, this would require substantial architectural changes that may not be immediately practical.
Incremental Improvement: Implement a more efficient visitor pattern similar to Webpack's hook system. For example, we currently have two rename operations:
structLabelRenamer{}implVisitorMutforLabelRenamer{fnvisit_label(){rename_label()}}structPrivateRenamer{}implVisitorMutforPrivateRenamer{fnvisit_private_ident(){rename_private_ident()}}fnrename(){
node.visit_mut_with(LabelRenamer);
node.visit_mut_with(PrivateRenamer);//~^ It means we should traverses twice.}
If we implement a hook-based approach, the minifier would only need to traverse the AST once. This single traversal could then trigger all necessary transformations through registered hooks:
structWebpackHooksLikeVisitor{plugins:Vec<Box<dynNodeMutablePlugin>>}implWebpackHooksLikeVisitor{fnvisit_private_ident(){self.plugins.run(private_ident_node)}fnvisit_label(){self.plugins.run(label_node)}}structLabelRenamer;implNodeMutablePluginforLabelRenamer{fnvisit_label(){rename_label();true// means continue visit}}structPrivateRenamer;implNodeMutablePluginforPrivateRename{fnvisit_private_ident(){rename_private_ident()
true // means continue visit}}fnrename(){let plugins = vec![Box(LabelRenamer),Box(PrivateRenamer)]let visitor = WebpackHooksLikeVisitor::new(root_node);
visitor.visit_root_node();}
We can merge the unrelated visitors to improve performance.
The text was updated successfully, but these errors were encountered: