mirror of
https://github.com/oxc-project/oxc.git
synced 2026-11-04 10:29:58 +00:00
perf(linter/react/rules-of-hooks): reduce allocs (#28473)
Currently, we allocate a Vec that is proportional in size to the total number of control flow graph (CFG) nodes. Instead, we can start with a SmallVec that ensures small CFG graphs never even allocate on the heap, and then grow as needed for larger graphs. On local fixtures: Allocated bytes: 21.11 MB → 48.13 kB (−99.77%). Maximum peak growth: 2.92 MB → 4.50 kB. --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
1 parent
b138c20bf3
commit
69f0204a0a
1 file changed
+4
-5
@@ -1,7 +1,8 @@
|
||||
use std::borrow::Cow;
|
||||
|
||||
use lazy_regex::Regex;
|
||||
use rustc_hash::{FxBuildHasher, FxHashSet};
|
||||
use rustc_hash::FxHashSet;
|
||||
use smallvec::SmallVec;
|
||||
|
||||
use oxc_ast::{
|
||||
AstKind, FunctionKind,
|
||||
@@ -616,11 +617,9 @@ fn has_conditional_path_accept_throw(
|
||||
let from_graph_id = nodes.cfg_id(from.id());
|
||||
let to_graph_id = nodes.cfg_id(to.id());
|
||||
let graph = cfg.graph();
|
||||
let block_count = graph.node_count();
|
||||
let mut stack = Vec::with_capacity(block_count);
|
||||
let mut stack = SmallVec::<[_; 8]>::new();
|
||||
stack.push((from_graph_id, false));
|
||||
let mut visited =
|
||||
FxHashSet::with_capacity_and_hasher(block_count.saturating_mul(2), FxBuildHasher);
|
||||
let mut visited = FxHashSet::default();
|
||||
|
||||
while let Some((block_id, passed_hook)) = stack.pop() {
|
||||
if !visited.insert((block_id, passed_hook)) {
|
||||
|
||||
Reference in new issue
Block a user