<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>143506</bug_id>
          
          <creation_ts>2015-04-07 17:58:29 -0700</creation_ts>
          <short_desc>Lazily initialize LogToSystemConsole flag to reduce memory usage</short_desc>
          <delta_ts>2015-04-08 11:28:10 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>JavaScriptCore</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Michael Saboff">msaboff</reporter>
          <assigned_to name="Michael Saboff">msaboff</assigned_to>
          <cc>commit-queue</cc>
    
    <cc>ggaren</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1083503</commentid>
    <comment_count>0</comment_count>
    <who name="Michael Saboff">msaboff</who>
    <bug_when>2015-04-07 17:58:29 -0700</bug_when>
    <thetext>When USE(CF) is defined, JSGlobalObjectConsoleClient::initializeLogToSystemConsole() calls into CoreFoundation preferences code to get application defaults.  In tests that can increase memory usage over 300K.  We should lazily call initializeLogToSystemConsole() to avoid this memory penalty.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1083504</commentid>
    <comment_count>1</comment_count>
    <who name="Michael Saboff">msaboff</who>
    <bug_when>2015-04-07 17:59:04 -0700</bug_when>
    <thetext>rdar://problem/20443393</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1083505</commentid>
    <comment_count>2</comment_count>
      <attachid>250321</attachid>
    <who name="Michael Saboff">msaboff</who>
    <bug_when>2015-04-07 18:05:46 -0700</bug_when>
    <thetext>Created attachment 250321
Patch

Note: style failure is in existing code that got moved.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1083506</commentid>
    <comment_count>3</comment_count>
    <who name="WebKit Commit Bot">commit-queue</who>
    <bug_when>2015-04-07 18:08:16 -0700</bug_when>
    <thetext>Attachment 250321 did not pass style-queue:


ERROR: Source/JavaScriptCore/inspector/JSGlobalObjectConsoleClient.cpp:50:  Missing space before {  [whitespace/braces] [5]
Total errors found: 1 in 2 files


If any of these errors are false positives, please file a bug against check-webkit-style.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1083513</commentid>
    <comment_count>4</comment_count>
      <attachid>250321</attachid>
    <who name="Mark Lam">mark.lam</who>
    <bug_when>2015-04-07 18:49:26 -0700</bug_when>
    <thetext>Comment on attachment 250321
Patch

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

r=me

&gt; Source/JavaScriptCore/inspector/JSGlobalObjectConsoleClient.cpp:50
&gt; +        std::call_once(initializeLogging, []{

Need a space between &apos;[]&apos; and &apos;{&apos;?

&gt; Source/JavaScriptCore/inspector/JSGlobalObjectConsoleClient.cpp:68
&gt; +    // If setLogToSystemConsole() was called, no need to query the default value.
&gt; +    if (sSetLogToSystemConsole)
&gt; +        return;
&gt; +

I think you can change this to an assert.  No one else should be calling this function anyway.  The original code was expecting to be only executed once only.

You can also make this function private in the header file.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1083559</commentid>
    <comment_count>5</comment_count>
    <who name="Michael Saboff">msaboff</who>
    <bug_when>2015-04-07 23:19:04 -0700</bug_when>
    <thetext>(In reply to comment #4)
&gt; Comment on attachment 250321 [details]
&gt; Patch
&gt; 
&gt; View in context:
&gt; https://bugs.webkit.org/attachment.cgi?id=250321&amp;action=review
&gt; 
&gt; r=me

Thanks for the review.
 
&gt; &gt; Source/JavaScriptCore/inspector/JSGlobalObjectConsoleClient.cpp:50
&gt; &gt; +        std::call_once(initializeLogging, []{
&gt; 
&gt; Need a space between &apos;[]&apos; and &apos;{&apos;?

The style bot wants the space, but I kept it with the original formatting as I think that adjacent makes more sense.

&gt; &gt; Source/JavaScriptCore/inspector/JSGlobalObjectConsoleClient.cpp:68
&gt; &gt; +    // If setLogToSystemConsole() was called, no need to query the default value.
&gt; &gt; +    if (sSetLogToSystemConsole)
&gt; &gt; +        return;
&gt; &gt; +
&gt; 
&gt; I think you can change this to an assert.  No one else should be calling
&gt; this function anyway.  The original code was expecting to be only executed
&gt; once only.

Actually that if is needed.  In the prior code, this run-once initializer always ran before the setter and getter could be called.  Now, the setter could be called before this run-once function and we don&apos;t want this run-once initializers to possible overwrite the value of sLogToSystemConsole.  This &quot;if&quot; protects that case.

&gt; You can also make this function private in the header file.

I&apos;ll do that.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1083601</commentid>
    <comment_count>6</comment_count>
    <who name="Michael Saboff">msaboff</who>
    <bug_when>2015-04-08 07:04:18 -0700</bug_when>
    <thetext>Committed r182535: &lt;http://trac.webkit.org/changeset/182535&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1083660</commentid>
    <comment_count>7</comment_count>
    <who name="Geoffrey Garen">ggaren</who>
    <bug_when>2015-04-08 11:04:44 -0700</bug_when>
    <thetext>I don&apos;t think this fix is sufficient, since the memory use will still happen after the first call to console.log.

We&apos;ve seen -- both in the web space and the embedded space -- that client code likes to leave in all its debugging console.log calls even in production. So, we need to make this memory savings stick even after the first call to console.log.

This should be achievable by just arranging not to do any of this work when the inspector is disabled. JoePeck recently made a change like this.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1083664</commentid>
    <comment_count>8</comment_count>
    <who name="Michael Saboff">msaboff</who>
    <bug_when>2015-04-08 11:12:29 -0700</bug_when>
    <thetext>(In reply to comment #7)
&gt; I don&apos;t think this fix is sufficient, since the memory use will still happen
&gt; after the first call to console.log.
&gt; 
&gt; We&apos;ve seen -- both in the web space and the embedded space -- that client
&gt; code likes to leave in all its debugging console.log calls even in
&gt; production. So, we need to make this memory savings stick even after the
&gt; first call to console.log.
&gt; 
&gt; This should be achievable by just arranging not to do any of this work when
&gt; the inspector is disabled. JoePeck recently made a change like this.

If we disable the inspector at compile time, we don&apos;t hit this path.

If the inspector is enabled at compile time, we need to store the console output for a possible subsequent attach by a remote inspector.

The memory usage is due to calling into CFPreferencesGetAppBooleanValue().</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1083671</commentid>
    <comment_count>9</comment_count>
    <who name="Geoffrey Garen">ggaren</who>
    <bug_when>2015-04-08 11:28:10 -0700</bug_when>
    <thetext>&gt; If the inspector is enabled at compile time, we need to store the console
&gt; output for a possible subsequent attach by a remote inspector.

No. We can detect that the inspector is not enabled.

&gt; The memory usage is due to calling into CFPreferencesGetAppBooleanValue().

Got it.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>250321</attachid>
            <date>2015-04-07 18:05:46 -0700</date>
            <delta_ts>2015-04-07 18:49:44 -0700</delta_ts>
            <desc>Patch</desc>
            <filename>143506.patch</filename>
            <type>text/plain</type>
            <size>2918</size>
            <attacher name="Michael Saboff">msaboff</attacher>
            
              <data encoding="base64">SW5kZXg6IFNvdXJjZS9KYXZhU2NyaXB0Q29yZS9DaGFuZ2VMb2cKPT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PQotLS0gU291
cmNlL0phdmFTY3JpcHRDb3JlL0NoYW5nZUxvZwkocmV2aXNpb24gMTgyNTExKQorKysgU291cmNl
L0phdmFTY3JpcHRDb3JlL0NoYW5nZUxvZwkod29ya2luZyBjb3B5KQpAQCAtMSwzICsxLDE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ci0gICAgc3RkOjpjYWxsX29uY2UoaW5pdGlhbGl6ZUxvZ2dpbmcsIFtdewot
ICAgICAgICBKU0dsb2JhbE9iamVjdENvbnNvbGVDbGllbnQ6OmluaXRpYWxpemVMb2dUb1N5c3Rl
bUNvbnNvbGUoKTsKLSAgICB9KTsKIH0KIAogdm9pZCBKU0dsb2JhbE9iamVjdENvbnNvbGVDbGll
bnQ6Om1lc3NhZ2VXaXRoVHlwZUFuZExldmVsKE1lc3NhZ2VUeXBlIHR5cGUsIE1lc3NhZ2VMZXZl
bCBsZXZlbCwgSlNDOjpFeGVjU3RhdGUqIGV4ZWMsIFJlZlB0cjxTY3JpcHRBcmd1bWVudHM+JiYg
YXJndW1lbnRzKQo=
</data>
<flag name="review"
          id="275121"
          type_id="1"
          status="+"
          setter="mark.lam"
    />
          </attachment>
      

    </bug>

</bugzilla>