Skip to content

Commit

Permalink
Reduce chrome.dll size by careful use of static_library
Browse files Browse the repository at this point in the history
Linking with a source_set tells the linker to pull in all of the code
and data from the specified object files, and then discard those that
can be proved to be unnecessary. This can cause extraneous global
variables and code to be retained, which has led to a regression in the
size of chrome.dll in gn builds, compared to gyp builds.

This change avoids linking in three arrays from ffmpeg. All of these
arrays have multiple instances, each half the size of the previous, so
the listed sizes below should all be doubled. The necessary changes were
tracked down by using dia2dump to find large global variables and then
running a python script to find the chain of object files that caused
these global to be pulled in. The arrays are:

ff_cos_65536_fixed - 64 KB, fixed by a previous ffmpeg change which enables these fixes.
ff_sin_65536 - 128 KiB is defined in ffmpeg's rdft.c. Pulled in by:
- service_worker_network_provider.obj, through //content/child:child
- render_frame_observer.obj, through //content/public/renderer:renderer_sources
- render_widget_mus_connection.obj, //content/renderer/mus:mus
- resource_converter.obj, through //content/renderer:renderer
ff_cos_65536 - 128 KiB is defined in ffmpeg's fft_template.c which is #included by fft_float.c. Pulled in by:
- audio_video_metadata_extractor.obj and media_file_checker.obj, through //media/base:base

Changing ffmpeg and the five source_set targets to static_library targets (conditionally in some cases) means that these arrays no longer get pulled in.

The expected in-memory savings in the .data section are (64+128+128)*2 KiB = 640 KiB. Actual savings were 718 KiB. This does not affect file size.

In addition this saved 288 KiB of code in the .text section, and shrunk the read-only data section, for a 301 KiB file-size savings.

Before: size of chrome.dll is 38.808576 MB
      name:   mem size  ,  disk size
     .text: 30.999296 MB
    .rdata:  6.007834 MB
     .data:  1.447656 MB,  0.270336 MB

After: size of chrome.dll is 38.499840 MB
      name:   mem size  ,  disk size
     .text: 30.704163 MB
    .rdata:  6.006906 MB
     .data:  0.712680 MB,  0.270336 MB

Measurements were done on 32-bit official builds from hash b8c16c8. Still some more work to be done.

BUG=624274

Review-Url: https://codereview.chromium.org/2163823002
Cr-Commit-Position: refs/heads/master@{#406611}
  • Loading branch information
randomascii authored and Commit bot committed Jul 20, 2016
1 parent f3b32b7 commit 058b59c
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 5 deletions.
7 changes: 6 additions & 1 deletion content/child/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import("//build/config/features.gni")
import("//build/config/ui.gni")
import("//content/child/child.gni")

source_set("child") {
if (is_component_build) {
link_target_type = "source_set"
} else {
link_target_type = "static_library"
}
target(link_target_type, "child") {
# Targets external to content should always link to the public API.
# Internal targets can link to this but only if they're child processes
# (i.e. not content/browser or content/common) and only if they're inside the
Expand Down
7 changes: 6 additions & 1 deletion content/public/renderer/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ group("renderer") {
}
}

source_set("renderer_sources") {
if (is_component_build) {
link_target_type = "source_set"
} else {
link_target_type = "static_library"
}
target(link_target_type, "renderer_sources") {
# External code should depend on via ":renderer" above.
visibility = [ "//content/*" ]

Expand Down
7 changes: 6 additions & 1 deletion content/renderer/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ import("//media/media_options.gni")
import("//third_party/webrtc/build/webrtc.gni")
import("//tools/ipc_fuzzer/ipc_fuzzer.gni")

source_set("renderer") {
if (is_component_build) {
link_target_type = "source_set"
} else {
link_target_type = "static_library"
}
target(link_target_type, "renderer") {
# Only the public target should depend on this. All other targets (even
# internal content ones) should depend on the public one.
visibility = [
Expand Down
2 changes: 1 addition & 1 deletion content/renderer/mus/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

source_set("mus") {
static_library("mus") {
# Depend on this only via //content/renderer.
visibility = [ "//content/renderer/*" ]

Expand Down
7 changes: 6 additions & 1 deletion media/base/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ config("base_config") {
]
}

source_set("base") {
if (is_component_build) {
link_target_type = "source_set"
} else {
link_target_type = "static_library"
}
target(link_target_type, "base") {
# This is part of the media component.
visibility = [ "//media/*" ]
sources = [
Expand Down

0 comments on commit 058b59c

Please sign in to comment.