<?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>112303</bug_id>
          
          <creation_ts>2013-03-13 17:43:33 -0700</creation_ts>
          <short_desc>[meta] Reduce startup mallocs</short_desc>
          <delta_ts>2023-12-25 10:07:22 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>WebCore Misc.</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>INVALID</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          <dependson>112736</dependson>
    
    <dependson>112769</dependson>
    
    <dependson>112831</dependson>
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Adam Barth">abarth</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>annevk</cc>
    
    <cc>ap</cc>
    
    <cc>benjamin</cc>
    
    <cc>eric</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>854821</commentid>
    <comment_count>0</comment_count>
    <who name="Adam Barth">abarth</who>
    <bug_when>2013-03-13 17:43:33 -0700</bug_when>
    <thetext>The profile for startup is has a lot of malloc-related samples.  We should reduce the number of mallocs we perform on startup to improve startup performance.  Here are the heaviest stacks for malloc on chromium-linux in DumpRenderTree:

   - tc_malloc
      - 23.76% WTF::fastMalloc(unsigned long)
         - 29.95% WTF::StringImpl::createFromLiteral(char const*, unsigned int)
            - WTF::AtomicString::addFromLiteralData(char const*, unsigned int)
               + 59.36% WebCore::createQualifiedName(void*, char const*, unsigned int, WTF::AtomicString const&amp;)
               + 29.88% WebCore::EventNames::EventNames()
               + 10.76% WebCore::createQualifiedName(void*, char const*, unsigned int)
         - 18.95% WTF::StringImpl::createUninitialized(unsigned int, unsigned char*&amp;)
            - 78.44% WTF::StringImpl::create(unsigned char const*, unsigned int)
                 WTF::StringImpl::create(unsigned char const*)
                 WTF::String::String(char const*)
                 WebKit::WebView::removeAllUserContent()
                 WebTestRunner::TestRunner::reset()
                 WebTestRunner::TestInterfaces::resetAll()
                 TestShell::resetTestController()
                 runTest(TestShell&amp;, TestParams&amp;, std::string const&amp;, bool)
                 main
                 __libc_start_main
            - 21.56% WTF::StringBuilder::allocateBuffer(unsigned char const*, unsigned int)
                 WebCore::InspectorValue::toJSONString() const
                 WebCore::InspectorCompositeState::inspectorStateUpdated()
                 WebCore::InspectorState::setValue(WTF::String const&amp;, WTF::PassRefPtr&lt;WebCore::InspectorValue&gt;)
                 WebCore::InspectorDebuggerAgent::InspectorDebuggerAgent(WebCore::InstrumentingAgents*, WebCore::InspectorCompositeState*, WebCore
                 WebCore::PageDebuggerAgent::PageDebuggerAgent(WebCore::InstrumentingAgents*, WebCore::InspectorCompositeState*, WebCore::Inspecto
                 WebCore::PageDebuggerAgent::create(WebCore::InstrumentingAgents*, WebCore::InspectorCompositeState*, WebCore::InspectorPageAgent*
                 WebCore::InspectorController::InspectorController(WebCore::Page*, WebCore::InspectorClient*)
                 WebCore::InspectorController::create(WebCore::Page*, WebCore::InspectorClient*)
                 WebCore::Page::Page(WebCore::Page::PageClients&amp;)
                 WebKit::WebViewImpl::WebViewImpl(WebKit::WebViewClient*)
                 WebKit::WebView::create(WebKit::WebViewClient*)
                 TestShell::createNewWindow(WebKit::WebURL const&amp;, DRTDevToolsAgent*, WebTestRunner::WebTestInterfaces*)
                 TestShell::createMainWindow()
                 main
                 __libc_start_main
         - 14.18% WebCore::QualifiedName::QualifiedName(WTF::AtomicString const&amp;, WTF::AtomicString const&amp;, WTF::AtomicString const&amp;)
              WebCore::createQualifiedName(void*, char const*, unsigned int)
              WebCore::SVGNames::init()
              WebCore::Frame::create(WebCore::Page*, WebCore::HTMLFrameOwnerElement*, WebCore::FrameLoaderClient*)
              WebKit::WebFrameImpl::initializeAsMainFrame(WebCore::Page*)
              WebKit::WebViewImpl::initializeMainFrame(WebKit::WebFrameClient*)
              TestShell::createNewWindow(WebKit::WebURL const&amp;, DRTDevToolsAgent*, WebTestRunner::WebTestInterfaces*)
              TestShell::createMainWindow()
              main
              __libc_start_main
         - 13.44% WTF::Vector&lt;WebCore::MediaPlayerFactory*, 0ul&gt;::expandCapacity(unsigned long)
              void WTF::Vector&lt;WebCore::MediaPlayerFactory*, 0ul&gt;::appendSlowCase&lt;WebCore::MediaPlayerFactory*&gt;(WebCore::MediaPlayerFactory* const
              WebCore::addMediaEngine(WTF::PassOwnPtr&lt;WebCore::MediaPlayerPrivateInterface&gt; (*)(WebCore::MediaPlayer*), void (*)(WTF::HashSet&lt;WTF:
              WebCore::installedMediaEngines(WebCore::RequeryEngineOptions)
              WebCore::MediaPlayer::isAvailable()
              WebCore::V8DOMWindow::GetTemplate(v8::Isolate*, WebCore::WrapperWorldType)
              WebCore::V8PerContextData::constructorForTypeSlowCase(WebCore::WrapperTypeInfo*)
              WebCore::V8DOMWindowShell::installDOMWindow()
              WebCore::V8DOMWindowShell::initializeIfNeeded()
              WebCore::ScriptController::windowShell(WebCore::DOMWrapperWorld*)
              WebCore::ScriptController::mainWorldContext(WebCore::Frame*)
              WebKit::WebFrameImpl::mainWorldScriptContext() const
              WebKit::WebTestingSupport::resetInternalsObject(WebKit::WebFrame*)
              TestShell::resetTestController()
              runTest(TestShell&amp;, TestParams&amp;, std::string const&amp;, bool)
              main
              __libc_start_main
         + 11.06% WebCore::CSSValuePool::createValue(double, WebCore::CSSPrimitiveValue::UnitTypes)
         + 5.62% WebCore::ResourceHandle::create(WebCore::NetworkingContext*, WebCore::ResourceRequest const&amp;, WebCore::ResourceHandleClient*, boo
         + 4.21% WTF::CStringBuffer::createUninitialized(unsigned long)
         + 2.59% WebCore::isolatedWorldMap()
      + 18.29% v8::internal::Malloced::New(unsigned long)
        13.95% g_malloc
        3.74% 0x6e000061746100
      + 3.70% 0x7fffabf1b1e0
        3.69% 0x7f7075181995
        3.68% 0x7f7075181a55
        3.67% FcStrStaticName
        3.66% XML_GetBuffer
        3.64% 0x7f7075181678
        3.35% _xcb_in_read
        2.88% __alloc_dir
        2.52% _nl_make_l10nflist</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>854911</commentid>
    <comment_count>1</comment_count>
    <who name="Benjamin Poulain">benjamin</who>
    <bug_when>2013-03-13 20:35:29 -0700</bug_when>
    <thetext>I worked on this a couple of month ago. WebCore::createQualifiedName() is already an optimized version for startup time.

There is one more crazy thing we can do about it: instead of allocating all the StringImpl one by one, we could allocated one buffer and build the StringImpl in there.

The other mallocs are new to me.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>854931</commentid>
    <comment_count>2</comment_count>
    <who name="Adam Barth">abarth</who>
    <bug_when>2013-03-13 21:16:16 -0700</bug_when>
    <thetext>I&apos;m going to try to lay out all the StringImpls statically at compile time.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>855257</commentid>
    <comment_count>3</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2013-03-14 09:44:24 -0700</bug_when>
    <thetext>See also: bug 61024.

Note that static allocation of mutable data is quite bad for memory use.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>855274</commentid>
    <comment_count>4</comment_count>
    <who name="Adam Barth">abarth</who>
    <bug_when>2013-03-14 10:04:19 -0700</bug_when>
    <thetext>&gt; Note that static allocation of mutable data is quite bad for memory use.

Is that a concern here?  The discussion on that bug seems to be about features that might not be used.  The mallocs we&apos;re talking about here happen on every startup.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>855291</commentid>
    <comment_count>5</comment_count>
    <who name="Benjamin Poulain">benjamin</who>
    <bug_when>2013-03-14 10:23:58 -0700</bug_when>
    <thetext>&gt; Is that a concern here?  The discussion on that bug seems to be about features that might not be used.  The mallocs we&apos;re talking about here happen on every startup.

I think he was just expressing general concerns.

I have wanted those StringImpl to be completely statically built for a while (hashmap and 16bits strings included).
I think if done correctly, we can make the Names initialization almost free.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>855293</commentid>
    <comment_count>6</comment_count>
    <who name="Benjamin Poulain">benjamin</who>
    <bug_when>2013-03-14 10:24:38 -0700</bug_when>
    <thetext>(I meant compile time Hash, not HashMap)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>855299</commentid>
    <comment_count>7</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2013-03-14 10:30:05 -0700</bug_when>
    <thetext>Yes, I think that it remains a concern. But I&apos;m sure that improvements can be made while keeping it in mind.

1. We&apos;ll need to ensure that the data is allocated contiguously in linked binary, so that touching it doesn&apos;t dirty more pages than necessary.

2. Ideally, this static allocation will be done in a way that doesn&apos;t immediately make the memory dirty. If it&apos;s done this way, touching e.g. one EventName could dirty more pages than necessary.

(1) is could cause a memory use regression from what we have now. (2) can not be a regression, it&apos;s an improvement opportunity. Ordering EventNames by how common they are could save some memory.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2001932</commentid>
    <comment_count>8</comment_count>
    <who name="Anne van Kesteren">annevk</who>
    <bug_when>2023-12-25 10:07:22 -0800</bug_when>
    <thetext>Let&apos;s close this. Someone would have to do fresh profiling at this point so it&apos;s not really meaningful to keep this around.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>