Skip to content
Browse files

style: Try to allocate possible size for AnimationValueMap before com…


The EffectSet count does not exactly represent the count what we really need
for AnimationValueMap, but in most cases it matches.  For example;

1) The element has two different keyframes animations

 @Keyframes anim1 {
   to { opacity: 0; }
 @Keyframes anim2 {
   to { transform: rotate(360deg); }

 In this case the number matches.

2) The element has two animations but both keyframes have the same CSS property

 @Keyframes anim1 {
   to { opacity: 0; }
 @Keyframes anim2 {
   to { opacity: 0.1; }

 In this case the number doesn't match, moreover it results more memory than we
 ever needed, but this case is presumably less common.

3) The element has an animation having keyframes for two different CSS

 @Keyframes anim {
   from { opacity: 0; transform: rotate(360deg); }

 In this kind of cases, the number doesn't match.  But even so, this patch
 reduces the opportunities that the AnimationValueMap tries to allocate a new
 memory (i.e. less opportunities on expanding the map).

Note that when the hash map is expanded, we do allocate a new RawTable with the
new size then replace the old one with the new one [1], so I believe this
change will reduce the crash rate to some extent.


Bug: 1418806
Reviewed-by: birtles
MozReview-Commit-ID: 6tcF9aqXh7a
  • Loading branch information
Hiroyuki Ikezoe authored and emilio committed Jun 30, 2018
1 parent d307b34 commit 2274f392d81fd5a575323b163d1b96bc0d857716
Showing with 10 additions and 1 deletion.
  1. +10 −1 components/style/gecko/
@@ -37,6 +37,7 @@ use gecko_bindings::bindings::Gecko_ElementHasAnimations;
use gecko_bindings::bindings::Gecko_ElementHasCSSAnimations;
use gecko_bindings::bindings::Gecko_ElementHasCSSTransitions;
use gecko_bindings::bindings::Gecko_GetActiveLinkAttrDeclarationBlock;
use gecko_bindings::bindings::Gecko_GetAnimationEffectCount;
use gecko_bindings::bindings::Gecko_GetAnimationRule;
use gecko_bindings::bindings::Gecko_GetExtraContentStyleDeclarations;
use gecko_bindings::bindings::Gecko_GetHTMLPresentationAttrDeclarationBlock;
@@ -948,8 +949,16 @@ fn get_animation_rule(
cascade_level: CascadeLevel,
) -> Option<Arc<Locked<PropertyDeclarationBlock>>> {
use gecko_bindings::sugar::ownership::HasSimpleFFI;
use properties::longhands::ANIMATABLE_PROPERTY_COUNT;

// There's a very rough correlation between the number of effects
// (animations) on an element and the number of properties it is likely to
// animate, so we use that as an initial guess for the size of the
// AnimationValueMap in order to reduce the number of re-allocations needed.
let effect_count = unsafe { Gecko_GetAnimationEffectCount(element.0) };
// Also, we should try to reuse the PDB, to avoid creating extra rule nodes.
let mut animation_values = AnimationValueMap::default();
let mut animation_values = AnimationValueMap::with_capacity_and_hasher(
effect_count.min(ANIMATABLE_PROPERTY_COUNT), Default::default());
if unsafe {

0 comments on commit 2274f39

Please sign in to comment.
You can’t perform that action at this time.