Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(716)

Issue 2920663002: Class/struct layout optimization for blink Resource related classes (Closed)

Created:
3 years, 6 months ago by stanisc
Modified:
3 years, 6 months ago
CC:
chromium-reviews, mlamouri+watch-content_chromium.org, caseq+blink_chromium.org, creis+watch_chromium.org, blink-reviews-api_chromium.org, nasko+codewatch_chromium.org, jam, tyoshino+watch_chromium.org, lushnikov+blink_chromium.org, loading-reviews+fetch_chromium.org, pfeldman+blink_chromium.org, dglazkov+blink, platform-architecture-syd+reviews-web_chromium.org, darin-cc_chromium.org, gavinp+loader_chromium.org, devtools-reviews_chromium.org, blink-reviews, apavlov+blink_chromium.org, kinuko+watch, Nate Chapin, loading-reviews_chromium.org, kozyatinskiy+blink_chromium.org
Target Ref:
refs/heads/master
Project:
chromium
Visibility:
Public.

Description

Class/struct layout optimization for blink Resource related classes Reduces sizeof(Resource) by 160 bytes from 1632 bytes to 1472 bytes. Also the following nested classes are optimized: - ResourceRequest - 416 to 368 bytes - ResourceResponse - 696 to 624 bytes - ResourceLoaderOptions 112 to 88 bytes The optimization is achieved by a combination of the following methods: 1) Making enums based on uint8_t or int8_t which reduces their size from 4 bytes to 1 byte. 2) Packing smaller sizing fields together forming 8 byte groups of fields to avoid padding. 3) Grouping bitfields together - disperse bitfields waste a lot of space due to padding The total number of Resource instances is typically 200-500 depending on site so the expected memory improvement is may be up to 100 KB per tab. But the change is straightforward and low risk. Here is an example of optimization. Before: class blink::ResourceResponse [sizeof = 696] { data +0x00 [sizeof=112] blink::KURL url_ data +0x70 [sizeof=8] WTF::AtomicString mime_type_ data +0x78 [sizeof=8] __int64 expected_content_length_ data +0x80 [sizeof=8] WTF::AtomicString text_encoding_name_ data +0x88 [sizeof=4] int http_status_code_ <padding> (4 bytes) data +0x90 [sizeof=8] WTF::AtomicString http_status_text_ data +0x98 [sizeof=24] blink::HTTPHeaderMap http_header_fields_ data +0xb0 [sizeof=1] bool was_cached_ : 1 <padding> (3 bytes) data +0xb4 [sizeof=4] unsigned int connection_id_ data +0xb8 [sizeof=1] bool connection_reused_ : 1 <padding> (7 bytes) data +0xc0 [sizeof=8] WTF::RefPtr<blink::ResourceLoadTiming> resource_load_timing_ data +0xc8 [sizeof=8] WTF::RefPtr<blink::ResourceLoadInfo> resource_load_info_ data +0xd0 [sizeof=1] bool is_null_ : 1 <padding> (7 bytes) data +0xd8 [sizeof=16] blink::CacheControlHeader cache_control_header_ data +0xe8 [sizeof=1] bool have_parsed_age_header_ : 1 data +0xe8 [sizeof=1] bool have_parsed_date_header_ : 1 data +0xe8 [sizeof=1] bool have_parsed_expires_header_ : 1 data +0xe8 [sizeof=1] bool have_parsed_last_modified_header_ : 1 <padding> (7 bytes) data +0xf0 [sizeof=8] double age_ data +0xf8 [sizeof=8] double date_ data +0x100 [sizeof=8] double expires_ data +0x108 [sizeof=8] double last_modified_ data +0x110 [sizeof=1] bool has_major_certificate_errors_ <padding> (3 bytes) data +0x114 [sizeof=4] blink::ResourceResponse::SecurityStyle security_style_ data +0x118 [sizeof=120] blink::ResourceResponse::SecurityDetails security_details_ data +0x190 [sizeof=4] blink::ResourceResponse::HTTPVersion http_version_ <padding> (4 bytes) data +0x198 [sizeof=8] __int64 app_cache_id_ data +0x1a0 [sizeof=112] blink::KURL app_cache_manifest_url_ data +0x210 [sizeof=16] WTF::Vector<char,0,WTF::PartitionAllocator> multipart_boundary_ data +0x220 [sizeof=1] bool was_fetched_via_spdy_ data +0x221 [sizeof=1] bool was_fetched_via_proxy_ data +0x222 [sizeof=1] bool was_fetched_via_service_worker_ data +0x223 [sizeof=1] bool was_fetched_via_foreign_fetch_ data +0x224 [sizeof=1] bool was_fallback_required_by_service_worker_ <padding> (3 bytes) data +0x228 [sizeof=4] blink::WebServiceWorkerResponseType service_worker_response_type_ <padding> (4 bytes) data +0x230 [sizeof=16] WTF::Vector<blink::KURL,0,WTF::PartitionAllocator> url_list_via_service_worker_ data +0x240 [sizeof=8] WTF::String cache_storage_cache_name_ data +0x248 [sizeof=16] WTF::Vector<WTF::String,0,WTF::PartitionAllocator> cors_exposed_header_names_ data +0x258 [sizeof=1] bool did_service_worker_navigation_preload_ <padding> (7 bytes) data +0x260 [sizeof=8] __int64 response_time_ data +0x268 [sizeof=8] WTF::AtomicString remote_ip_address_ data +0x270 [sizeof=2] unsigned short remote_port_ <padding> (6 bytes) data +0x278 [sizeof=8] __int64 encoded_data_length_ data +0x280 [sizeof=8] __int64 encoded_body_length_ data +0x288 [sizeof=8] __int64 decoded_body_length_ data +0x290 [sizeof=8] WTF::String downloaded_file_path_ data +0x298 [sizeof=8] WTF::RefPtr<blink::BlobDataHandle> downloaded_file_handle_ data +0x2a0 [sizeof=8] WTF::RefPtr<blink::ResourceResponse::ExtraData> extra_data_ data +0x2a8 [sizeof=16] WTF::Vector<blink::ResourceResponse,0,WTF::PartitionAllocator> redirect_responses_ } After: class blink::ResourceResponse [sizeof = 624] { data +0x00 [sizeof=112] blink::KURL url_ data +0x70 [sizeof=8] WTF::AtomicString mime_type_ data +0x78 [sizeof=8] __int64 expected_content_length_ data +0x80 [sizeof=8] WTF::AtomicString text_encoding_name_ data +0x88 [sizeof=4] unsigned int connection_id_ data +0x8c [sizeof=4] int http_status_code_ data +0x90 [sizeof=8] WTF::AtomicString http_status_text_ data +0x98 [sizeof=24] blink::HTTPHeaderMap http_header_fields_ data +0xb0 [sizeof=8] WTF::AtomicString remote_ip_address_ data +0xb8 [sizeof=2] unsigned short remote_port_ data +0xba [sizeof=1] bool was_cached_ : 1 data +0xba [sizeof=1] bool connection_reused_ : 1 data +0xba [sizeof=1] bool is_null_ : 1 data +0xba [sizeof=1] bool have_parsed_age_header_ : 1 data +0xba [sizeof=1] bool have_parsed_date_header_ : 1 data +0xba [sizeof=1] bool have_parsed_expires_header_ : 1 data +0xba [sizeof=1] bool have_parsed_last_modified_header_ : 1 data +0xba [sizeof=1] bool has_major_certificate_errors_ : 1 data +0xbb [sizeof=1] bool was_fetched_via_spdy_ : 1 data +0xbb [sizeof=1] bool was_fetched_via_proxy_ : 1 data +0xbb [sizeof=1] bool was_fetched_via_service_worker_ : 1 data +0xbb [sizeof=1] bool was_fetched_via_foreign_fetch_ : 1 data +0xbb [sizeof=1] bool was_fallback_required_by_service_worker_ : 1 data +0xbb [sizeof=1] bool did_service_worker_navigation_preload_ : 1 data +0xbc [sizeof=1] blink::WebServiceWorkerResponseType service_worker_response_type_ data +0xbd [sizeof=1] blink::ResourceResponse::HTTPVersion http_version_ data +0xbe [sizeof=1] blink::ResourceResponse::SecurityStyle security_style_ <padding> (1 bytes) data +0xc0 [sizeof=120] blink::ResourceResponse::SecurityDetails security_details_ data +0x138 [sizeof=8] WTF::RefPtr<blink::ResourceLoadTiming> resource_load_timing_ data +0x140 [sizeof=8] WTF::RefPtr<blink::ResourceLoadInfo> resource_load_info_ data +0x148 [sizeof=16] blink::CacheControlHeader cache_control_header_ data +0x158 [sizeof=8] double age_ data +0x160 [sizeof=8] double date_ data +0x168 [sizeof=8] double expires_ data +0x170 [sizeof=8] double last_modified_ data +0x178 [sizeof=8] __int64 app_cache_id_ data +0x180 [sizeof=112] blink::KURL app_cache_manifest_url_ data +0x1f0 [sizeof=16] WTF::Vector<char,0,WTF::PartitionAllocator> multipart_boundary_ data +0x200 [sizeof=16] WTF::Vector<blink::KURL,0,WTF::PartitionAllocator> url_list_via_service_worker_ data +0x210 [sizeof=8] WTF::String cache_storage_cache_name_ data +0x218 [sizeof=16] WTF::Vector<WTF::String,0,WTF::PartitionAllocator> cors_exposed_header_names_ data +0x228 [sizeof=8] __int64 response_time_ data +0x230 [sizeof=8] __int64 encoded_data_length_ data +0x238 [sizeof=8] __int64 encoded_body_length_ data +0x240 [sizeof=8] __int64 decoded_body_length_ data +0x248 [sizeof=8] WTF::String downloaded_file_path_ data +0x250 [sizeof=8] WTF::RefPtr<blink::BlobDataHandle> downloaded_file_handle_ data +0x258 [sizeof=8] WTF::RefPtr<blink::ResourceResponse::ExtraData> extra_data_ data +0x260 [sizeof=16] WTF::Vector<blink::ResourceResponse,0,WTF::PartitionAllocator> redirect_responses_ } BUG=710933 Review-Url: https://codereview.chromium.org/2920663002 Cr-Commit-Position: refs/heads/master@{#479798} Committed: https://chromium.googlesource.com/chromium/src/+/a8599ca28499cb5770adc9219857b3a0dff4b90b

Patch Set 1 #

Total comments: 8

Patch Set 2 : Addressed feedback #

Total comments: 2

Patch Set 3 : Addressed second round of feedback #

Patch Set 4 : Rebase #

Unified diffs Side-by-side diffs Delta from patch set Stats (+157 lines, -155 lines) Patch
M content/public/renderer/associated_resource_fetcher.h View 1 2 chunks +1 line, -1 line 0 comments Download
M content/renderer/fetchers/associated_resource_fetcher_impl.h View 1 2 chunks +1 line, -1 line 0 comments Download
M content/renderer/fetchers/multi_resolution_image_resource_fetcher.h View 1 2 chunks +1 line, -1 line 0 comments Download
M content/renderer/internal_document_state_data.h View 1 1 chunk +0 lines, -1 line 0 comments Download
M content/renderer/render_frame_impl.h View 1 2 3 2 chunks +1 line, -1 line 0 comments Download
M third_party/WebKit/Source/core/frame/FrameTestHelpers.h View 1 2 3 2 chunks +1 line, -1 line 0 comments Download
M third_party/WebKit/Source/core/inspector/InspectorTraceEvents.h View 1 2 2 chunks +1 line, -2 lines 0 comments Download
M third_party/WebKit/Source/core/loader/HistoryItem.h View 1 2 chunks +1 line, -1 line 0 comments Download
M third_party/WebKit/Source/platform/loader/fetch/FetchContext.h View 1 2 2 chunks +1 line, -1 line 0 comments Download
M third_party/WebKit/Source/platform/loader/fetch/IntegrityMetadata.h View 1 chunk +5 lines, -1 line 0 comments Download
M third_party/WebKit/Source/platform/loader/fetch/Resource.h View 1 2 3 5 chunks +9 lines, -10 lines 0 comments Download
M third_party/WebKit/Source/platform/loader/fetch/Resource.cpp View 1 2 3 1 chunk +6 lines, -6 lines 0 comments Download
M third_party/WebKit/Source/platform/loader/fetch/ResourceLoadPriority.h View 1 chunk +1 line, -1 line 0 comments Download
M third_party/WebKit/Source/platform/loader/fetch/ResourceLoaderOptions.h View 1 2 4 chunks +14 lines, -10 lines 0 comments Download
M third_party/WebKit/Source/platform/loader/fetch/ResourceRequest.h View 1 6 chunks +6 lines, -8 lines 0 comments Download
M third_party/WebKit/Source/platform/loader/fetch/ResourceRequest.cpp View 1 2 3 6 chunks +6 lines, -6 lines 0 comments Download
M third_party/WebKit/Source/platform/loader/fetch/ResourceResponse.h View 5 chunks +45 lines, -45 lines 0 comments Download
M third_party/WebKit/Source/platform/loader/fetch/ResourceResponse.cpp View 7 chunks +42 lines, -42 lines 0 comments Download
M third_party/WebKit/Source/platform/weborigin/ReferrerPolicy.h View 1 2 3 1 chunk +1 line, -1 line 0 comments Download
M third_party/WebKit/public/platform/WebCachePolicy.h View 2 chunks +2 lines, -2 lines 0 comments Download
M third_party/WebKit/public/platform/WebURLRequest.h View 1 2 3 9 chunks +11 lines, -11 lines 0 comments Download
M third_party/WebKit/public/platform/modules/serviceworker/WebServiceWorkerResponseType.h View 1 chunk +1 line, -1 line 0 comments Download
M third_party/WebKit/public/web/WebLocalFrame.h View 1 2 3 1 chunk +0 lines, -1 line 0 comments Download

Messages

Total messages: 39 (20 generated)
stanisc
drott@chromium.org: Please review changes in WebKit/Source/platform dcheng@chromium.org: Please review changes in WebKit/Source/core, WebKit/Source/web/tests, and WebKit/public ...
3 years, 6 months ago (2017-06-05 18:00:50 UTC) #10
dcheng
Miscellaneous questions: 1) is there some long-term plan to help maintain good packing order? 2) ...
3 years, 6 months ago (2017-06-05 18:15:41 UTC) #11
drott
I am more comfortable reviewing things in platform/fonts - If possible, I suggest to find ...
3 years, 6 months ago (2017-06-06 07:32:03 UTC) #12
stanisc
+noel@ for WebKit/Source/platform > 1) is there some long-term plan to help maintain good packing ...
3 years, 6 months ago (2017-06-06 22:47:55 UTC) #16
dcheng
https://codereview.chromium.org/2920663002/diff/20001/third_party/WebKit/Source/platform/loader/fetch/Resource.h File third_party/WebKit/Source/platform/loader/fetch/Resource.h (right): https://codereview.chromium.org/2920663002/diff/20001/third_party/WebKit/Source/platform/loader/fetch/Resource.h#newcode436 third_party/WebKit/Source/platform/loader/fetch/Resource.h:436: bool needs_synchronous_cache_hit_ : 1; On 2017/06/06 22:47:55, stanisc wrote: ...
3 years, 6 months ago (2017-06-07 17:09:23 UTC) #17
kinuko
We've removed bitfield sometime ago as we didn't think it was beneficial, I'm not fully ...
3 years, 6 months ago (2017-06-08 05:26:45 UTC) #19
stanisc
On 2017/06/08 05:26:45, kinuko wrote: > We've removed bitfield sometime ago as we didn't think ...
3 years, 6 months ago (2017-06-08 16:23:06 UTC) #20
stanisc
I've moved some of the fields back and changed bitfields back to bool in Resource.h. ...
3 years, 6 months ago (2017-06-08 21:34:04 UTC) #21
kinuko
One more question- I'm fine with this change ifself if this doesn't make readability worse, ...
3 years, 6 months ago (2017-06-09 04:12:32 UTC) #25
Noel Gordon
On 2017/06/06 22:47:55, stanisc wrote: > +noel@ for WebKit/Source/platform japhet@ would be the appropriate reviewer ...
3 years, 6 months ago (2017-06-09 05:31:16 UTC) #26
stanisc
On 2017/06/09 04:12:32, kinuko wrote: > One more question- I'm fine with this change ifself ...
3 years, 6 months ago (2017-06-09 18:45:29 UTC) #27
stanisc
+brucedawson@
3 years, 6 months ago (2017-06-09 18:48:07 UTC) #28
brucedawson
On 2017/06/09 18:48:07, stanisc wrote: > +brucedawson@ I definitely understand the concerns about this just ...
3 years, 6 months ago (2017-06-09 23:36:54 UTC) #29
dcheng
LGTM It will likely regress without monitoring (which I'm cautiously optimistic we can eventually warn ...
3 years, 6 months ago (2017-06-14 18:09:47 UTC) #30
dcheng
(I just want to make sure that we balance out logical grouping of fields with ...
3 years, 6 months ago (2017-06-14 18:10:34 UTC) #31
alexmos
content/ LGTM
3 years, 6 months ago (2017-06-14 21:44:28 UTC) #32
kinuko
On 2017/06/09 18:45:29, stanisc wrote: > On 2017/06/09 04:12:32, kinuko wrote: > > One more ...
3 years, 6 months ago (2017-06-14 23:25:41 UTC) #33
commit-bot: I haz the power
CQ is trying da patch. Follow status at: https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.org/2920663002/100001
3 years, 6 months ago (2017-06-15 17:43:50 UTC) #36
commit-bot: I haz the power
3 years, 6 months ago (2017-06-15 19:55:48 UTC) #39
Message was sent while issue was closed.
Committed patchset #4 (id:100001) as
https://chromium.googlesource.com/chromium/src/+/a8599ca28499cb5770adc9219857...

Powered by Google App Engine
This is Rietveld 408576698