Skip to content

Commit

Permalink
Reduce chrome.exe .text size by 50 KB with static_library
Browse files Browse the repository at this point in the history
Also improves build times.

chrome.exe's .text (code) section in gn builds is about 55 KB larger
than in gyp builds (32-bit official). This is largely or completely
because of the use of source sets. The gn build links with about 320
.obj files whereas the gyp build links with ten. The linker pulls in
all of those .obj files and then fails to do a perfect job of discarding
the unused code and data.

This change gets rid of ~50 KB of this discrepancy by changing several
build targets from source_set to static_library and reducing the number
of .obj files to be linked to 72.

The size gain came from the change to components/variations, but the
other changes help to ensure that the size gain sticks, and help with
build speeds.

This change reduces the build times for relinking the affected
binaries (mostly chrome.dll and chrome_child.dll) in an official build
about 4-7%.

Some source_set targets could not be changed. These were annotated as
such to avoid wasting time on them in the future.

BUG=624274

Review-Url: https://codereview.chromium.org/2149483002
Cr-Commit-Position: refs/heads/master@{#405671}
  • Loading branch information
randomascii authored and Commit bot committed Jul 15, 2016
1 parent 4aab40a commit fe9b427
Show file tree
Hide file tree
Showing 16 changed files with 19 additions and 16 deletions.
2 changes: 1 addition & 1 deletion breakpad/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,7 @@ if (is_win) {
}
}

source_set("breakpad_handler") {
static_library("breakpad_handler") {
configs += [ ":handler_config" ]
if (is_win) {
public_configs = [ ":handler_config" ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ config("client_config") {
include_dirs = [ ".." ]
}

source_set("client") {
static_library("client") {
sources = [
"crash_report_database.cc",
"crash_report_database.h",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ config("compat_config") {
}
}

source_set("compat") {
static_library("compat") {
sources = []
if (is_mac) {
sources += [
Expand Down
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("handler_lib") {
static_library("handler_lib") {
sources = [
"crash_report_upload_thread.cc",
"crash_report_upload_thread.h",
Expand Down
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("minidump") {
static_library("minidump") {
deps = [
"../compat",
"../snapshot",
Expand Down
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("snapshot") {
static_library("snapshot") {
deps = [
"../client",
"../compat",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ if (is_mac) {
}
}

source_set("util") {
static_library("util") {
sources = [
"file/file_io.cc",
"file/file_io.h",
Expand Down
4 changes: 2 additions & 2 deletions build/secondary/third_party/libjpeg_turbo/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ if (current_cpu == "x86" || current_cpu == "x64") {
}
}

source_set("simd") {
static_library("simd") {
if (current_cpu == "x86") {
deps = [
":simd_asm",
Expand Down Expand Up @@ -141,7 +141,7 @@ config("libjpeg_config") {
include_dirs = [ "." ]
}

source_set("libjpeg") {
static_library("libjpeg") {
sources = [
"jcapimin.c",
"jcapistd.c",
Expand Down
2 changes: 1 addition & 1 deletion components/bookmarks/common/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("common") {
static_library("common") {
sources = [
"bookmark_constants.cc",
"bookmark_constants.h",
Expand Down
4 changes: 2 additions & 2 deletions components/browser_watcher/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("browser_watcher") {
static_library("browser_watcher") {
# This is a separate lib to minimize the dependencies for its
# hosting binary "chrome_watcher.dll".
sources = [
Expand All @@ -20,7 +20,7 @@ source_set("browser_watcher") {
]
}

source_set("browser_watcher_client") {
static_library("browser_watcher_client") {
sources = [
"watcher_client_win.cc",
"watcher_client_win.h",
Expand Down
2 changes: 1 addition & 1 deletion components/crash/content/app/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ static_library("lib") {
}

# GYP version: components/crash.gypi:crash_component
source_set("app") {
static_library("app") {
sources = [
"crash_switches.cc",
"crash_switches.h",
Expand Down
2 changes: 1 addition & 1 deletion components/variations/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ if (is_android) {
import("//build/config/android/rules.gni")
}

source_set("variations") {
static_library("variations") {
sources = [
"active_field_trials.cc",
"active_field_trials.h",
Expand Down
2 changes: 1 addition & 1 deletion mojo/public/cpp/bindings/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("bindings") {
static_library("bindings") {
sources = [
"array.h",
"array_traits.h",
Expand Down
2 changes: 1 addition & 1 deletion third_party/brotli/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ if (is_win) {
import("//build/config/win/visual_studio_version.gni")
}

source_set("brotli") {
static_library("brotli") {
sources = [
"dec/bit_reader.c",
"dec/bit_reader.h",
Expand Down
1 change: 1 addition & 0 deletions third_party/libpng/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ config("clang_warnings") {
}
}

# Cannot be a static_library in component builds
source_set("libpng_sources") {
sources = [
"png.c",
Expand Down
2 changes: 2 additions & 0 deletions ui/gfx/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@ group("selection_bound") {
}

# Depend on this to use selection_bound.h without pulling in all of gfx.
# Cannot be a static_library in component builds due to exported functions
source_set("selection_bound_sources") {
visibility = [ ":*" ]

Expand Down Expand Up @@ -499,6 +500,7 @@ group("memory_buffer") {
]
}
}
# Cannot be a static_library in component builds due to exported functions
source_set("memory_buffer_sources") {
visibility = [ ":*" ] # Depend on through ":memory_buffer".

Expand Down

0 comments on commit fe9b427

Please sign in to comment.