Bug 127171

Summary: Script make_names.pl should generate lazily created arrays for attributes and tags.
Product: WebKit Reporter: Vivek Galatage <vivekg>
Component: DOMAssignee: Vivek Galatage <vivekg>
Status: RESOLVED WONTFIX    
Severity: Normal CC: ahmad.saleem792, andersca, ap, benjamin, bfulgham, commit-queue, darin, esprehn+autocc, gyuyoung.kim, kangil.han, kling, rniwa
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch darin: review-

Description Vivek Galatage 2014-01-17 04:18:33 PST
Currently make_names.pl generate local static arrays for the tags and the attributes. 

These arrays hold pointers to the global data and these arrays are declared as 
static.

As the pointer data itself is global, the array need not be declared as static. We could create it lazily.

Also even though these functions, get{{namespace}}Tags/Attrs(), may not be called upon, the binary would still be loaded with 
allocation of that much amount of static data. 

Blink review URL: https://codereview.chromium.org/137783012/
Comment 1 Vivek Galatage 2014-01-17 04:26:52 PST
Created attachment 221455 [details]
Patch
Comment 2 Darin Adler 2014-01-17 09:08:14 PST
Comment on attachment 221455 [details]
Patch

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

> Source/WebCore/ChangeLog:17
> +        As the pointer data itself is global, the array need not be declared as static. 
> +        We could create it lazily.
> +
> +        Also even though these functions, get{{namespace}}Tags/Attrs(), may not be called upon,
> +        the binary would still be loaded with allocation of that much amount of static data. 

Doesn’t seem like a good tradeoff to me. In most systems, there is no significant cost to having static data that is never accessed, due to virtual memory and the OS. The code to build this structure seems like it will be significantly bigger than the data object.

Was there some specific case where this savings proved worthwhile? Could you give some numbers for the improvement?

> Source/WebCore/dom/make_names.pl:704
> +    printHeaderHead($F, "DOM", $parameters{namespace}, "#include \"QualifiedName.h\"\n#include <wtf/PassOwnPtr.h>\n");

This is wrong. Code doesn’t use PassOwnPtr.
Comment 3 Vivek Galatage 2014-01-17 09:20:59 PST
(In reply to comment #2)
> (From update of attachment 221455 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=221455&action=review
> 
> > Source/WebCore/ChangeLog:17
> > +        As the pointer data itself is global, the array need not be declared as static. 
> > +        We could create it lazily.
> > +
> > +        Also even though these functions, get{{namespace}}Tags/Attrs(), may not be called upon,
> > +        the binary would still be loaded with allocation of that much amount of static data. 
> 
> Doesn’t seem like a good tradeoff to me. In most systems, there is no significant cost to having static data that is never accessed, due to virtual memory and the OS. The code to build this structure seems like it will be significantly bigger than the data object.
> 
> Was there some specific case where this savings proved worthwhile? Could you give some numbers for the improvement?

I haven't calculated it specifically on Mac but did some measurements on linux and android using blink. Here is the link to the data saving table [1]. It saved us about 4.2kb from .data.rel.ro and .rel.dyn sections. Also saved about 360 relocations. The patch url also has array based approach [2]

[1] https://code.google.com/p/chromium/issues/detail?id=249746#c21
[2] https://codereview.chromium.org/137783012/#ps1

> 
> > Source/WebCore/dom/make_names.pl:704
> > +    printHeaderHead($F, "DOM", $parameters{namespace}, "#include \"QualifiedName.h\"\n#include <wtf/PassOwnPtr.h>\n");
> 
> This is wrong. Code doesn’t use PassOwnPtr.

Yeah this is not required.
Comment 4 Darin Adler 2014-01-17 11:34:13 PST
(In reply to comment #3)
> Here is the link to the data saving table [1]. It saved us about 4.2kb from .data.rel.ro and .rel.dyn sections. Also saved about 360 relocations.

How much did it add to the text section?
Comment 5 Vivek Galatage 2014-01-17 12:51:35 PST
(In reply to comment #4)
> (In reply to comment #3)
> > Here is the link to the data saving table [1]. It saved us about 4.2kb from .data.rel.ro and .rel.dyn sections. Also saved about 360 relocations.
> 
> How much did it add to the text section?

These arethe breakups

Section         Before      After        Diff

.text           24008156    24012876     +4720 (increased)
.data.rel.ro      995480      994040     -1440 (decreased)
.rel.dyn         1991888     1989008     -2880 (decreased)
                                         ------
                                          +400

So around 400 bytes were increased in the text section.
Comment 6 Vivek Galatage 2014-01-17 12:55:33 PST
+--------------------+--------------------------+
|                    |    Relocation Details    |
+   Detail           +------------+-------------+
|                    |    Before  |      After  |
+--------------------+------------+-------------+
| relocations        |     248986 |      248626 |
| relative (99%)     |     248935 |      248575 |
| PLT entries        |        338 |         338 |
| for local syms     |        338 |         338 |
+--------------------+------------+-------------+
Comment 7 Darin Adler 2014-01-17 13:35:13 PST
My thinking would be to leave this as-is. Replacing read-only data with code of the same size doesn’t seem like a win to me. Replacing process-load relocation time with “lazy creation” code at runtime might be a win, but a small one. If we’re really concerned about the cost of these relocations, maybe we can change the data structure so there are fewer pointers involved?
Comment 8 Darin Adler 2014-01-17 13:35:35 PST
But mine is not the only opinion that matters. I’d love to hear from other WebKit experts on this.
Comment 9 Darin Adler 2014-01-17 13:37:13 PST
(In reply to comment #7)
> Replacing read-only data with code of the same size doesn’t seem like a win to me.

I should have said “replacing read-only data with code that is slightly larger than that data”.
Comment 11 Ryosuke Niwa 2022-08-19 14:55:23 PDT
This is won't fix at this point.