New issue
Advanced search Search tips

Issue 636462 link

Starred by 1 user

Issue metadata

Status: Fixed
Owner:
Closed: Aug 2016
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: All
Pri: 3
Type: Bug



Sign in to add a comment

Don't overallocate in CachedMetadata

Project Member Reported by dskiba@chromium.org, Aug 10 2016

Issue description

CachedMetdata has a Vector<char> member and calls append() in its constructor. The problem is that Vector::append(data, size) calls expandCapacity(size), which allocates "(size / 4) + 1" more bytes than needed. Metadata can be quite large, 288 KiB was seen in [1], but that is a total number, which decomposes into 230 KiB of actual data and 58 KiB of wasted memory.

The fix is to reserve enough space, either by using Vector(size) constructor, or by explicitly calling reserveInitialCapacity(). Slightly involved fix is to add Vector(data, size) constructor, which might be useful in other places.

There is at least one other place where Vector::append() is called in a constructor: PushMessageData, but I suspect there are instances of this pattern in functions, too. It might be interesting to profile Vector and find out how many instances were not modified after first append().

[1] https://docs.google.com/spreadsheets/d/13knYGLMXB5opE7vlDUsvreNcYr-FEi_mmaJ2YZVfS6M/edit#gid=159723971
 
Components: -Blink>Internals Blink>Network>FetchAPI
Labels: -OS-Android OS-All
This should be an easy fix, just call reserveInitialCapacity in there. This class in general seems like it could be simplified, we should also move the constructors into the .cpp file so we're not inling all that Vector code everywhere.
Cc: haraken@chromium.org yhirano@chromium.org
Components: -Blink>Network>FetchAPI Blink>Loader
Cc: -yhirano@chromium.org
Owner: yhirano@chromium.org
Status: Assigned (was: Untriaged)
Project Member

Comment 5 by bugdroid1@chromium.org, Aug 31 2016

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/2805c285bf5a0b681c2ad648c0d5506aa26985d1

commit 2805c285bf5a0b681c2ad648c0d5506aa26985d1
Author: yhirano <yhirano@chromium.org>
Date: Wed Aug 31 02:41:24 2016

Reserve Vector's capacity manually in CachedMetadata

As CachedMetaData::m_serializedData is set only at the initialization timing,
we can call Vector<char>::reserveCapacity to save memory consumption without
loosing performance.

This CL includes other cleanups:

 - Renaming methods,
 - Replacing error handling logic with DCHECKs,
 - Replacing unsigned with uint32_t.

BUG= 636462 

Review-Url: https://codereview.chromium.org/2258743002
Cr-Commit-Position: refs/heads/master@{#415544}

[modify] https://crrev.com/2805c285bf5a0b681c2ad648c0d5506aa26985d1/third_party/WebKit/Source/bindings/core/v8/V8ScriptRunner.cpp
[modify] https://crrev.com/2805c285bf5a0b681c2ad648c0d5506aa26985d1/third_party/WebKit/Source/bindings/core/v8/V8ScriptRunner.h
[modify] https://crrev.com/2805c285bf5a0b681c2ad648c0d5506aa26985d1/third_party/WebKit/Source/core/core.gypi
[add] https://crrev.com/2805c285bf5a0b681c2ad648c0d5506aa26985d1/third_party/WebKit/Source/core/fetch/CachedMetadata.cpp
[modify] https://crrev.com/2805c285bf5a0b681c2ad648c0d5506aa26985d1/third_party/WebKit/Source/core/fetch/CachedMetadata.h
[modify] https://crrev.com/2805c285bf5a0b681c2ad648c0d5506aa26985d1/third_party/WebKit/Source/core/fetch/CachedMetadataHandler.h
[modify] https://crrev.com/2805c285bf5a0b681c2ad648c0d5506aa26985d1/third_party/WebKit/Source/core/fetch/Resource.cpp
[modify] https://crrev.com/2805c285bf5a0b681c2ad648c0d5506aa26985d1/third_party/WebKit/Source/modules/serviceworkers/ServiceWorkerScriptCachedMetadataHandler.cpp
[modify] https://crrev.com/2805c285bf5a0b681c2ad648c0d5506aa26985d1/third_party/WebKit/Source/modules/serviceworkers/ServiceWorkerScriptCachedMetadataHandler.h

Status: Fixed (was: Assigned)

Sign in to add a comment