mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Don't allocate in Dom::trace
even when debug assertions are enabled (#37487)
`Dom::trace` currently allocates a new string when debug assertions are
enabled:
0f61361e27/components/script_bindings/root.rs (L232-L241)
This allocation is very heavy in profiles (~14% of runtime). While it
doesn't affect production builds, these few characters are not providing
enough value to justify the cost.
This changes the method to instead only use `std::any::type_name`,
without `format!`. With this change, all the string-format related
methods vanish from the profile.
Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
This commit is contained in:
parent
f60e9cdff5
commit
048de52238
1 changed files with 6 additions and 6 deletions
|
@ -229,15 +229,15 @@ impl<T: DomObject> Deref for Dom<T> {
|
|||
}
|
||||
|
||||
unsafe impl<T: DomObject> JSTraceable for Dom<T> {
|
||||
unsafe fn trace(&self, trc: *mut JSTracer) {
|
||||
let trace_string;
|
||||
unsafe fn trace(&self, tracer: *mut JSTracer) {
|
||||
let trace_info = if cfg!(debug_assertions) {
|
||||
trace_string = format!("for {} on heap", ::std::any::type_name::<T>());
|
||||
&trace_string[..]
|
||||
std::any::type_name::<T>()
|
||||
} else {
|
||||
"for DOM object on heap"
|
||||
"DOM object on heap"
|
||||
};
|
||||
trace_reflector(trc, trace_info, (*self.ptr.as_ptr()).reflector());
|
||||
unsafe {
|
||||
trace_reflector(tracer, trace_info, (*self.ptr.as_ptr()).reflector());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue