mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
Auto merge of #18386 - bholley:unchecked_cssom_get, r=upsuper
Bypass the lock in get_property_value This measurably improves performance - see https://bugzilla.mozilla.org/show_bug.cgi?id=1355599#c21 <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/18386) <!-- Reviewable:end -->
This commit is contained in:
commit
e3568ba07a
2 changed files with 29 additions and 3 deletions
|
@ -176,6 +176,13 @@ impl<T> Locked<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Access the data for reading without verifying the lock. Use with caution.
|
||||||
|
#[cfg(feature = "gecko")]
|
||||||
|
pub unsafe fn read_unchecked<'a>(&'a self) -> &'a T {
|
||||||
|
let ptr = self.data.get();
|
||||||
|
&*ptr
|
||||||
|
}
|
||||||
|
|
||||||
/// Access the data for writing.
|
/// Access the data for writing.
|
||||||
pub fn write_with<'a>(&'a self, guard: &'a mut SharedRwLockWriteGuard) -> &'a mut T {
|
pub fn write_with<'a>(&'a self, guard: &'a mut SharedRwLockWriteGuard) -> &'a mut T {
|
||||||
assert!(self.same_lock_as(&guard.0),
|
assert!(self.same_lock_as(&guard.0),
|
||||||
|
|
|
@ -1124,6 +1124,20 @@ fn read_locked_arc<T, R, F>(raw: &<Locked<T> as HasFFI>::FFIType, func: F) -> R
|
||||||
func(Locked::<T>::as_arc(&raw).read_with(&guard))
|
func(Locked::<T>::as_arc(&raw).read_with(&guard))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(debug_assertions)]
|
||||||
|
unsafe fn read_locked_arc_unchecked<T, R, F>(raw: &<Locked<T> as HasFFI>::FFIType, func: F) -> R
|
||||||
|
where Locked<T>: HasArcFFI, F: FnOnce(&T) -> R
|
||||||
|
{
|
||||||
|
read_locked_arc(raw, func)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(debug_assertions))]
|
||||||
|
unsafe fn read_locked_arc_unchecked<T, R, F>(raw: &<Locked<T> as HasFFI>::FFIType, func: F) -> R
|
||||||
|
where Locked<T>: HasArcFFI, F: FnOnce(&T) -> R
|
||||||
|
{
|
||||||
|
func(Locked::<T>::as_arc(&raw).read_unchecked())
|
||||||
|
}
|
||||||
|
|
||||||
fn write_locked_arc<T, R, F>(raw: &<Locked<T> as HasFFI>::FFIType, func: F) -> R
|
fn write_locked_arc<T, R, F>(raw: &<Locked<T> as HasFFI>::FFIType, func: F) -> R
|
||||||
where Locked<T>: HasArcFFI, F: FnOnce(&mut T) -> R
|
where Locked<T>: HasArcFFI, F: FnOnce(&mut T) -> R
|
||||||
{
|
{
|
||||||
|
@ -2263,9 +2277,14 @@ macro_rules! get_property_id_from_property {
|
||||||
|
|
||||||
fn get_property_value(declarations: RawServoDeclarationBlockBorrowed,
|
fn get_property_value(declarations: RawServoDeclarationBlockBorrowed,
|
||||||
property_id: PropertyId, value: *mut nsAString) {
|
property_id: PropertyId, value: *mut nsAString) {
|
||||||
read_locked_arc(declarations, |decls: &PropertyDeclarationBlock| {
|
// This callsite is hot enough that the lock acquisition shows up in profiles.
|
||||||
decls.property_value_to_css(&property_id, unsafe { value.as_mut().unwrap() }).unwrap();
|
// Using an unchecked read here improves our performance by ~10% on the
|
||||||
})
|
// microbenchmark in bug 1355599.
|
||||||
|
unsafe {
|
||||||
|
read_locked_arc_unchecked(declarations, |decls: &PropertyDeclarationBlock| {
|
||||||
|
decls.property_value_to_css(&property_id, value.as_mut().unwrap()).unwrap();
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue