Bug 121744

Summary: Give purity hints to compiler to avoid penalizing repeated calls to some functions.
Product: WebKit Reporter: Andreas Kling <kling>
Component: WebCore JavaScriptAssignee: Andreas Kling <kling>
Status: RESOLVED FIXED    
Severity: Normal CC: andersca, benjamin, cmarcelo, commit-queue, darin, esprehn+autocc, glenn, kling, macpherson, menard
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch idea
darin: review+
Land for patching none

Description Andreas Kling 2013-09-21 09:23:28 PDT
Help the CSE a bit.
Comment 1 Andreas Kling 2013-09-21 09:29:31 PDT
Created attachment 212274 [details]
Patch idea
Comment 2 Darin Adler 2013-09-21 11:46:42 PDT
Comment on attachment 212274 [details]
Patch idea

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

Did you test? How well did this work?

> Source/WTF/wtf/Compiler.h:198
> +#define WTF_PURE_FUNCTION __attribute__ ((pure))

I never know if we should include the WTF prefixes. I would not like it if it was WTF_OVERRIDE, for example.

Also, I seem to recall that __attribute__((__pure__)) does the same thing and is a little more safe if someone has a macro named "pure".
Comment 3 Andreas Kling 2013-09-22 05:15:53 PDT
(In reply to comment #2)
> (From update of attachment 212274 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=212274&action=review
> 
> Did you test? How well did this work?

It knocks 4800 bytes off of the binary size, and does succeed in coalescing multiple function calls in the same function. Of course the real value is in calling threadGlobalData() as little as possible, since that has to do a pthread_getspecific().

> > Source/WTF/wtf/Compiler.h:198
> > +#define WTF_PURE_FUNCTION __attribute__ ((pure))
> 
> I never know if we should include the WTF prefixes. I would not like it if it was WTF_OVERRIDE, for example.

Let's just call it PURE_FUNCTION.

> Also, I seem to recall that __attribute__((__pure__)) does the same thing and is a little more safe if someone has a macro named "pure".

Good idea.
Comment 4 Andreas Kling 2013-09-22 05:16:32 PDT
Created attachment 212300 [details]
Land for patching
Comment 5 WebKit Commit Bot 2013-09-22 05:48:52 PDT
Comment on attachment 212300 [details]
Land for patching

Clearing flags on attachment: 212300

Committed r156246: <http://trac.webkit.org/changeset/156246>
Comment 6 WebKit Commit Bot 2013-09-22 05:48:54 PDT
All reviewed patches have been landed.  Closing bug.
Comment 7 Benjamin Poulain 2013-09-22 21:08:47 PDT
Comment on attachment 212300 [details]
Land for patching

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

Pure has plenty of advantages for function used cross-compilation unit. I am really happy you added a macro for it.

> Source/WTF/ChangeLog:11
> +        Marking a function pure means that the compiler's CSE pass is free to coalesce
> +        multiple calls to this function because it has no globally observable side
> +        effects beyond the first call.

I don't think the definition of pure has anything to do with the first call though.
I could not find a formal definition from a quick search in Clang's doc.