Bug 182165

Summary: JavaScriptCore builtins should be partially minified in Release builds not Debug builds
Product: WebKit Reporter: Joseph Pecoraro <joepeck>
Component: JavaScriptCoreAssignee: Joseph Pecoraro <joepeck>
Status: RESOLVED FIXED    
Severity: Normal CC: bburg, commit-queue, ews-watchlist, jlewis3, joepeck, keith_miller, mark.lam, msaboff, saam, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
[PATCH] Proposed Fix
none
[BEFORE] JSCBuiltins.cpp
none
[AFTER] JSCBuiltins.cpp
none
[PATCH] Proposed Fix
keith_miller: review+
[PATCH] Eliminate all leading whitespace version none

Description Joseph Pecoraro 2018-01-25 21:08:11 PST
JavaScriptCore builtins should be partially minified in Release builds not Debug builds

Added with:
<https://webkit.org/b/152290> Builtin source should be minified more
http://trac.webkit.org/changeset/194144

> diff --git a/Source/JavaScriptCore/Scripts/builtins/builtins_model.py b/Source/JavaScriptCore/Scripts/builtins/builtins_model.py
> old mode 100644
> new mode 100755
> index d765eca865e..cdd5f900354
> --- a/Source/JavaScriptCore/Scripts/builtins/builtins_model.py
> +++ b/Source/JavaScriptCore/Scripts/builtins/builtins_model.py
> @@ -100,6 +103,11 @@ class BuiltinFunction:
>      @staticmethod
>      def fromString(function_string):
>          function_source = multilineCommentRegExp.sub("", function_string)
> +        if os.getenv("CONFIGURATION", "Debug").startswith("Debug"):
> +            function_source = lineWithOnlySingleLineCommentRegExp.sub("", function_source)
> +            function_source = lineWithTrailingSingleLineCommentRegExp.sub("\n", function_source)
> +            function_source = multipleEmptyLinesRegExp.sub("\n", function_source)

Should have been `if os.getenv("CONFIGURATION", "Debug").startswith("Debug"):` otherwise we are only doing these optimizations for Debug builds.
Comment 1 Joseph Pecoraro 2018-01-25 21:23:29 PST
Example of the diff of a before/after the few minifications being applied:

    534c463
    < const int s_arrayPrototypeSomeCodeLength = 540;
    ---
    > const int s_arrayPrototypeSomeCodeLength = 460;
    539,554c468,480
    <     "    \"use strict\";\n" \
    <     "\n" \
    <     "    var array = @toObject(this, \"Array.prototype.some requires that |this| not be null or undefined\");\n" \
    <     "    var length = @toLength(array.length);\n" \
    <     "\n" \
    <     "    if (typeof callback !== \"function\")\n" \
    <     "        @throwTypeError(\"Array.prototype.some callback must be a function\");\n" \
    <     "    \n" \
    <     "    var thisArg = @argument(1);\n" \
    <     "    for (var i = 0; i < length; i++) {\n" \
    <     "        if (!(i in array))\n" \
    <     "            continue;\n" \
    <     "        if (callback.@call(thisArg, array[i], i, array))\n" \
    <     "            return true;\n" \
    <     "    }\n" \
    <     "    return false;\n" \
    ---
    >     "\"use strict\";\n" \
    >     "var array = @toObject(this, \"Array.prototype.some requires that |this| not be null or undefined\");\n" \
    >     "var length = @toLength(array.length);\n" \
    >     "if (typeof callback !== \"function\")\n" \
    >     " @throwTypeError(\"Array.prototype.some callback must be a function\");\n" \
    >     "var thisArg = @argument(1);\n" \
    >     "for (var i = 0; i < length; i++) {\n" \
    >     " if (!(i in array))\n" \
    >     "  continue;\n" \
    >     " if (callback.@call(thisArg, array[i], i, array))\n" \
    >     "  return true;\n" \
    >     "}\n" \
    >     "return false;\n" \

Lets see what tests will be affected.
Comment 2 Joseph Pecoraro 2018-01-25 21:25:25 PST
Created attachment 332350 [details]
[PATCH] Proposed Fix

Lets see what the bots think.
Comment 3 Joseph Pecoraro 2018-01-25 21:26:38 PST
Created attachment 332351 [details]
[BEFORE] JSCBuiltins.cpp
Comment 4 EWS Watchlist 2018-01-25 21:26:54 PST
This patch modifies the JS builtins code generator. Please ensure that you have rebaselined any generator test results (i.e., by running `Tools/Scripts/run-builtins-generator-tests --reset-results`)
Comment 5 Joseph Pecoraro 2018-01-25 21:26:57 PST
Created attachment 332352 [details]
[AFTER] JSCBuiltins.cpp
Comment 6 EWS Watchlist 2018-01-25 21:27:03 PST
Attachment 332350 [details] did not pass style-queue:


ERROR: Source/JavaScriptCore/Scripts/builtins/builtins_model.py:130:  expected 1 blank line, found 0  [pep8/E301] [5]
Total errors found: 1 in 2 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 7 Joseph Pecoraro 2018-01-25 21:28:23 PST
This would also minify WebCore's many built-ins, but those are spread across many files.
Comment 8 Keith Miller 2018-01-25 21:29:39 PST
Looks like you need to rebase.
Comment 9 Keith Miller 2018-01-25 21:34:07 PST
Comment on attachment 332350 [details]
[PATCH] Proposed Fix

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

r=me. I always wished we had a static UnlinkedBytecode for builtin js functions... that seems hard for non-webcore though. Also, why not just remove all extraneous whitespace? I doubt it would matter much in practice, though.

> Source/JavaScriptCore/Scripts/builtins/builtins_model.py:129
> -        if os.getenv("CONFIGURATION", "Debug").startswith("Debug"):
> +        if not os.getenv("CONFIGURATION", "Debug").startswith("Debug"):

Awesome!
Comment 10 Joseph Pecoraro 2018-01-25 21:34:08 PST
Created attachment 332353 [details]
[PATCH] Proposed Fix

Rebaselined.
Comment 11 EWS Watchlist 2018-01-25 21:36:07 PST
Attachment 332353 [details] did not pass style-queue:


ERROR: Source/JavaScriptCore/Scripts/builtins/builtins_model.py:130:  expected 1 blank line, found 0  [pep8/E301] [5]
Total errors found: 1 in 2 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 12 Joseph Pecoraro 2018-01-25 21:37:04 PST
(In reply to Keith Miller from comment #9)
> Comment on attachment 332350 [details]
> [PATCH] Proposed Fix
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=332350&action=review
> 
> r=me. I always wished we had a static UnlinkedBytecode for builtin js
> functions... that seems hard for non-webcore though. Also, why not just
> remove all extraneous whitespace? I doubt it would matter much in practice,
> though.

I just wanted a cheap solution to eliminate a lot of whitespace. I can entirely eliminate it in Release builds.

We could run the jsmin minifier eventually, but a concern there is our jsmin not knowing about new JavaScript syntax could choke and I didn't want something like that to block JavaScriptCore developers from building.
Comment 13 Joseph Pecoraro 2018-01-25 21:39:40 PST
In fact that is what I'll do. I'll eliminate all leading whitespace if the bots seem good with it, since thats an even easier patch. I'll put it up in parallel.
Comment 14 Joseph Pecoraro 2018-01-25 21:41:47 PST
Created attachment 332354 [details]
[PATCH] Eliminate all leading whitespace version
Comment 15 Keith Miller 2018-01-25 21:42:52 PST
(In reply to Joseph Pecoraro from comment #12)
> (In reply to Keith Miller from comment #9)
> > Comment on attachment 332350 [details]
> > [PATCH] Proposed Fix
> > 
> > View in context:
> > https://bugs.webkit.org/attachment.cgi?id=332350&action=review
> > 
> > r=me. I always wished we had a static UnlinkedBytecode for builtin js
> > functions... that seems hard for non-webcore though. Also, why not just
> > remove all extraneous whitespace? I doubt it would matter much in practice,
> > though.
> 
> I just wanted a cheap solution to eliminate a lot of whitespace. I can
> entirely eliminate it in Release builds.
> 
> We could run the jsmin minifier eventually, but a concern there is our jsmin
> not knowing about new JavaScript syntax could choke and I didn't want
> something like that to block JavaScriptCore developers from building.

Sure, I think the conversion to unlinked bytecode would solve that but minifying seems more expedient -- and less of a PITA for the build system --.
Comment 16 WebKit Commit Bot 2018-01-26 11:32:10 PST
Comment on attachment 332354 [details]
[PATCH] Eliminate all leading whitespace version

Clearing flags on attachment: 332354

Committed r227685: <https://trac.webkit.org/changeset/227685>
Comment 17 WebKit Commit Bot 2018-01-26 11:32:11 PST
All reviewed patches have been landed.  Closing bug.
Comment 18 Radar WebKit Bug Importer 2018-01-26 11:33:34 PST
<rdar://problem/36917860>
Comment 20 Joseph Pecoraro 2018-01-26 13:18:06 PST
(In reply to Matt Lewis from comment #19)
> This caused the builtins-generator-tests to fail.
> 
> https://build.webkit.org/builders/
> Apple%20High%20Sierra%20Release%20WK1%20(Tests)/builds/2977
> 
> https://build.webkit.org/builders/
> Apple%20High%20Sierra%20Release%20WK1%20(Tests)/builds/2977/steps/builtins-
> generator-tests/logs/stdio

These just need to be rebaselined now that our default behavior is to not minify (it was accidentally defaulting to minify before. I'll rebasline them.
Comment 21 Joseph Pecoraro 2018-01-26 13:23:59 PST
> These just need to be rebaselined now that our default behavior is to not
> minify (it was accidentally defaulting to minify before. I'll rebasline them.

<https://trac.webkit.org/r227693>