Remove unnecessary context allocation - #952
Conversation
5e999d4 to
fed5ec3
Compare
78d8c0f to
3bd9ea1
Compare
fed5ec3 to
f06bd59
Compare
3bd9ea1 to
8fac711
Compare
|
I find the lifecycle of For example, let mut context = self
.reusable_linearization_context
.take()
.expect("ancestor linearization must not be re-entered");
context.begin();
let result = self.linearize_ancestors(declaration_id, &mut context);
debug_assert!(context.is_idle());
self.reusable_linearization_context = Some(context);
resultThis retains the allocation benefit, while making the context’s lifetime and ownership at a traversal call site easier to reason about. Using By the way, a 12% speedup from allocation reduction alone seems a little surprising. What is actually driving the improvement? |
Currently, we are allocating a new
LinearizationContexteach time forancestors_of. This is completely unnecessary because the linearization recursion already cleans up the context object.We can simply reuse the same object stored in the
Resolver, avoid the allocation entirely and removeancestors_ofwhile we're at it. This provides a 12% speed up for resolution, bringing us to ~11s.