Bug 224586 - Use WTF::Function instead of std::function in SVGPropertyAnimatorFactory::attributeAnimatorCreator
Summary: Use WTF::Function instead of std::function in SVGPropertyAnimatorFactory::att...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Alex Christensen
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-04-14 16:29 PDT by Alex Christensen
Modified: 2021-04-15 11:24 PDT (History)
13 users (show)

See Also:


Attachments
Patch (22.75 KB, patch)
2021-04-14 16:35 PDT, Alex Christensen
no flags Details | Formatted Diff | Diff
Patch (22.73 KB, patch)
2021-04-14 19:17 PDT, Alex Christensen
no flags Details | Formatted Diff | Diff
Patch (21.94 KB, patch)
2021-04-15 10:00 PDT, Alex Christensen
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Alex Christensen 2021-04-14 16:29:28 PDT
Use WTF::Function instead of std::function in SVGPropertyAnimatorFactory::attributeAnimatorCreator
Comment 1 Alex Christensen 2021-04-14 16:35:17 PDT
Created attachment 426061 [details]
Patch
Comment 2 Geoffrey Garen 2021-04-14 16:39:36 PDT
Comment on attachment 426061 [details]
Patch

EWS too angry
Comment 3 Alex Christensen 2021-04-14 19:17:14 PDT
Created attachment 426068 [details]
Patch
Comment 4 Darin Adler 2021-04-15 08:49:05 PDT
Comment on attachment 426068 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=426068&action=review

> Source/WebCore/ChangeLog:9
> +        sizeof(WTF::Function<void()>) is 8.
> +        sizeof(std::function<void()>) is 48.

What about total memory use? I’m wondering if we should even allow std::function if it uses more memory, but maybe this is more about "what's in the top level of the object and what's on the heap"?

> Source/WebCore/svg/properties/SVGPropertyAnimatorFactory.h:112
> +            Pair { SVGNames::colorAttr->impl(),              std::make_pair(SVGValueProperty<Color>::create, SVGPropertyAnimatorFactory::createColorAnimator) },

Is there a good reason we are using std::make_pair instead of just brace syntax? Could we make this even tighter?
Comment 5 Chris Dumez 2021-04-15 08:51:24 PDT
(In reply to Darin Adler from comment #4)
> Comment on attachment 426068 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=426068&action=review
> 
> > Source/WebCore/ChangeLog:9
> > +        sizeof(WTF::Function<void()>) is 8.
> > +        sizeof(std::function<void()>) is 48.
> 
> What about total memory use? I’m wondering if we should even allow
> std::function if it uses more memory, but maybe this is more about "what's
> in the top level of the object and what's on the heap"?
> 
> > Source/WebCore/svg/properties/SVGPropertyAnimatorFactory.h:112
> > +            Pair { SVGNames::colorAttr->impl(),              std::make_pair(SVGValueProperty<Color>::create, SVGPropertyAnimatorFactory::createColorAnimator) },
> 
> Is there a good reason we are using std::make_pair instead of just brace
> syntax? Could we make this even tighter?

My understanding is that std::function tries to be smart about when to store the data inline or do a heap allocation. It makes this determination based on the size of the data. WTF::Function always does a heap allocation no matter the size of the data.
Comment 6 Alex Christensen 2021-04-15 10:00:10 PDT
Created attachment 426112 [details]
Patch
Comment 7 Alex Christensen 2021-04-15 10:14:00 PDT
Comment on attachment 426112 [details]
Patch

I'm not sure about heap/inline memory use total, but I do know that inside a HashMap we want inline to be smaller.
Comment 8 Alex Christensen 2021-04-15 10:38:56 PDT
r276033
Comment 9 Darin Adler 2021-04-15 11:24:57 PDT
(In reply to Alex Christensen from comment #7)
> I'm not sure about heap/inline memory use total, but I do know that inside a
> HashMap we want inline to be smaller.

Sure, but at a certain point for hash tables we will do that by putting the whole thing on the heap, not by building the capability into classes.

For something we are using as widely as WTF::Function our lens should be broader than just suitability in hash tables.