Skip to content

Commit

Permalink
Reduce includes of windows.h
Browse files Browse the repository at this point in the history
Windows.h is included in a number of key header files which means that
a majority of the translation units when building Chrome include
Windows.h. This is slowing down builds.

This change creates a new header - base/win/windows_types.h - which
contains typedefs and defines of common Windows.h types - and uses this
in place of windows.h in enough places to reduce the number of
translation units that include windows.h in a build of the 'chrome'
target (debug component non-jumbo) by 5219, from 19041 to 13822, giving
measurable build-time speedups (~2.5-3.0%).

Follow-up changes will apply the same techniques to more headers and
drop the number much further.

Perversely enough, this change also adds includes of windows.h in many
places - places that always needed windows.h but were implicitly
depending on it being included elsewhere.

[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected]
TBRing mechanical changes, reviewers:
jochen@ : Please review changes to chrome/, components/, content/, third_party/WebKit/Source/platform
wfh@ : Please review changes to courgette/, sandbox/win
rockot@ : Please review changes to device/, ipc/, services/
mef@ : Please review changes to net/
raymes@ : Please review changes to ppapi/
joedow@ : Please review changes to remoting/
rogerta@ : Please review changes to rlz/
jsbell@: Please review changes to storage/
dpranke@ : Please review changes to tools/gn/
sky@ : Please review changes to ui/


Bug: 796644,798763
Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel;master.tryserver.chromium.android:android_optional_gpu_tests_rel;master.tryserver.chromium.linux:linux_optional_gpu_tests_rel;master.tryserver.chromium.mac:mac_optional_gpu_tests_rel;master.tryserver.chromium.win:win_optional_gpu_tests_rel
Change-Id: I3958d0d7d813bed74d9b166e0358dbde5b5729af
Reviewed-on: https://chromium-review.googlesource.com/846422
Commit-Queue: Bruce Dawson <[email protected]>
Reviewed-by: Misha Efimov <[email protected]>
Reviewed-by: Scott Violet <[email protected]>
Reviewed-by: John Abd-El-Malek <[email protected]>
Reviewed-by: Daniel Cheng <[email protected]>
Cr-Commit-Position: refs/heads/master@{#526881}
  • Loading branch information
randomascii authored and Commit Bot committed Jan 4, 2018
1 parent 2e824f4 commit bfdc3fd
Show file tree
Hide file tree
Showing 104 changed files with 542 additions and 50 deletions.
1 change: 1 addition & 0 deletions base/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -2331,6 +2331,7 @@ test("base_unittests") {
"win/shortcut_unittest.cc",
"win/startup_information_unittest.cc",
"win/wait_chain_unittest.cc",
"win/win_includes_unittest.cc",
"win/win_util_unittest.cc",
"win/windows_version_unittest.cc",
"win/winrt_storage_util_unittest.cc",
Expand Down
2 changes: 2 additions & 0 deletions base/allocator/allocator_shim_override_ucrt_symbols_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

#include <malloc.h>

#include <windows.h>

extern "C" {

void* (*malloc_unchecked)(size_t) = &base::allocator::UncheckedAlloc;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include "build/build_config.h"

#if defined(OS_WIN)
#include <windows.h> // Must be in front of other Windows header files.

#include <VersionHelpers.h>
#endif

Expand Down
26 changes: 14 additions & 12 deletions base/atomicops_internals_x86_msvc.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#ifndef BASE_ATOMICOPS_INTERNALS_X86_MSVC_H_
#define BASE_ATOMICOPS_INTERNALS_X86_MSVC_H_

#include <windows.h>
#include "base/win/windows_types.h"

#include <intrin.h>

Expand Down Expand Up @@ -61,8 +61,10 @@ inline void MemoryBarrier() {
// See #undef and note at the top of this file.
__faststorefence();
#else
// We use MemoryBarrier from WinNT.h
::MemoryBarrier();
// We use the implementation of MemoryBarrier from WinNT.h
LONG barrier;

_InterlockedOr(&barrier, 0);
#endif
}

Expand Down Expand Up @@ -115,25 +117,25 @@ static_assert(sizeof(Atomic64) == sizeof(PVOID), "atomic word is atomic");
inline Atomic64 NoBarrier_CompareAndSwap(volatile Atomic64* ptr,
Atomic64 old_value,
Atomic64 new_value) {
PVOID result = InterlockedCompareExchangePointer(
reinterpret_cast<volatile PVOID*>(ptr),
reinterpret_cast<PVOID>(new_value), reinterpret_cast<PVOID>(old_value));
PVOID result = _InterlockedCompareExchangePointer(
reinterpret_cast<volatile PVOID*>(ptr),
reinterpret_cast<PVOID>(new_value), reinterpret_cast<PVOID>(old_value));
return reinterpret_cast<Atomic64>(result);
}

inline Atomic64 NoBarrier_AtomicExchange(volatile Atomic64* ptr,
Atomic64 new_value) {
PVOID result = InterlockedExchangePointer(
reinterpret_cast<volatile PVOID*>(ptr),
reinterpret_cast<PVOID>(new_value));
PVOID result =
_InterlockedExchangePointer(reinterpret_cast<volatile PVOID*>(ptr),
reinterpret_cast<PVOID>(new_value));
return reinterpret_cast<Atomic64>(result);
}

inline Atomic64 Barrier_AtomicIncrement(volatile Atomic64* ptr,
Atomic64 increment) {
return InterlockedExchangeAdd64(
reinterpret_cast<volatile LONGLONG*>(ptr),
static_cast<LONGLONG>(increment)) + increment;
return _InterlockedExchangeAdd64(reinterpret_cast<volatile LONGLONG*>(ptr),
static_cast<LONGLONG>(increment)) +
increment;
}

inline Atomic64 NoBarrier_AtomicIncrement(volatile Atomic64* ptr,
Expand Down
2 changes: 2 additions & 0 deletions base/files/file_path_watcher_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include "base/time/time.h"
#include "base/win/object_watcher.h"

#include <windows.h>

namespace base {

namespace {
Expand Down
2 changes: 1 addition & 1 deletion base/files/file_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include "build/build_config.h"

#if defined(OS_WIN)
#include <windows.h>
#include "base/win/windows_types.h"
#elif defined(OS_POSIX)
#include <sys/stat.h>
#include <unistd.h>
Expand Down
2 changes: 2 additions & 0 deletions base/files/file_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include "base/metrics/histogram_functions.h"
#include "base/threading/thread_restrictions.h"

#include <windows.h>

namespace base {

// Make sure our Whence mappings match the system headers.
Expand Down
2 changes: 2 additions & 0 deletions base/files/memory_mapped_file_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include "base/strings/string16.h"
#include "base/threading/thread_restrictions.h"

#include <windows.h>

namespace base {

MemoryMappedFile::MemoryMappedFile() : data_(NULL), length_(0) {
Expand Down
2 changes: 1 addition & 1 deletion base/files/platform_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#include "build/build_config.h"

#if defined(OS_WIN)
#include <windows.h>
#include "base/win/scoped_handle.h"
#include "base/win/windows_types.h"
#endif

// This file defines platform-independent types for dealing with
Expand Down
1 change: 1 addition & 0 deletions base/memory/discardable_shared_memory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#endif

#if defined(OS_WIN)
#include <windows.h>
#include "base/win/windows_version.h"
#endif

Expand Down
2 changes: 1 addition & 1 deletion base/memory/shared_memory_handle.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
#include "build/build_config.h"

#if defined(OS_WIN)
#include <windows.h>
#include "base/process/process_handle.h"
#include "base/win/windows_types.h"
#elif defined(OS_MACOSX) && !defined(OS_IOS)
#include <mach/mach.h>
#include "base/base_export.h"
Expand Down
2 changes: 2 additions & 0 deletions base/memory/shared_memory_handle_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "base/logging.h"
#include "base/unguessable_token.h"

#include <windows.h>

namespace base {

SharedMemoryHandle::SharedMemoryHandle() {}
Expand Down
1 change: 1 addition & 0 deletions base/metrics/persistent_memory_allocator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <algorithm>

#if defined(OS_WIN)
#include <windows.h>
#include "winbase.h"
#elif defined(OS_POSIX)
#include <sys/mman.h>
Expand Down
3 changes: 2 additions & 1 deletion base/process/memory_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

#include "base/process/memory.h"

#include <windows.h> // Must be in front of other Windows header files.

#include <new.h>
#include <psapi.h>
#include <stddef.h>
#include <windows.h>

// malloc_unchecked is required to implement UncheckedMalloc properly.
// It's provided by allocator_shim_win.cc but since that's not always present,
Expand Down
2 changes: 1 addition & 1 deletion base/process/process_handle.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "build/build_config.h"

#if defined(OS_WIN)
#include <windows.h>
#include "base/win/windows_types.h"
#endif

#if defined(OS_FUCHSIA)
Expand Down
7 changes: 7 additions & 0 deletions base/process/process_metrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,20 @@

#if defined(OS_WIN)
#include "base/win/scoped_handle.h"
#include "base/win/windows_types.h"
#endif

namespace base {

#if defined(OS_WIN)
// _WINDOWS_ will be defined if Windows.h was included - include Windows.h first
// to get access to the full struct definition.
#if defined(_WINDOWS_)
struct IoCounters : public IO_COUNTERS {
};
#else
struct IoCounters;
#endif
#elif defined(OS_POSIX)
struct IoCounters {
uint64_t ReadOperationCount;
Expand Down
4 changes: 3 additions & 1 deletion base/process/process_metrics_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Must be included before process_metrics.h to get full IoCounters definition
#include <windows.h>

#include "base/process/process_metrics.h"

#include <windows.h>
#include <psapi.h>
#include <stddef.h>
#include <stdint.h>
Expand Down
2 changes: 2 additions & 0 deletions base/process/process_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include "base/process/kill.h"
#include "base/threading/thread_restrictions.h"

#include <windows.h>

namespace {

DWORD kBasicProcessAccess =
Expand Down
6 changes: 3 additions & 3 deletions base/synchronization/condition_variable.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
#endif

#if defined(OS_WIN)
#include <windows.h>
#include "base/win/windows_types.h"
#endif

namespace base {
Expand Down Expand Up @@ -105,8 +105,8 @@ class BASE_EXPORT ConditionVariable {
private:

#if defined(OS_WIN)
CONDITION_VARIABLE cv_;
SRWLOCK* const srwlock_;
CHROME_CONDITION_VARIABLE cv_;
CHROME_SRWLOCK* const srwlock_;
#elif defined(OS_POSIX)
pthread_cond_t condition_;
pthread_mutex_t* user_mutex_;
Expand Down
12 changes: 8 additions & 4 deletions base/synchronization/condition_variable_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include "base/threading/thread_restrictions.h"
#include "base/time/time.h"

#include <windows.h>

namespace base {

ConditionVariable::ConditionVariable(Lock* user_lock)
Expand All @@ -18,7 +20,7 @@ ConditionVariable::ConditionVariable(Lock* user_lock)
#endif
{
DCHECK(user_lock);
InitializeConditionVariable(&cv_);
InitializeConditionVariable(reinterpret_cast<PCONDITION_VARIABLE>(&cv_));
}

ConditionVariable::~ConditionVariable() = default;
Expand All @@ -36,7 +38,9 @@ void ConditionVariable::TimedWait(const TimeDelta& max_time) {
user_lock_->CheckHeldAndUnmark();
#endif

if (!SleepConditionVariableSRW(&cv_, srwlock_, timeout, 0)) {
if (!SleepConditionVariableSRW(reinterpret_cast<PCONDITION_VARIABLE>(&cv_),
reinterpret_cast<PSRWLOCK>(srwlock_), timeout,
0)) {
// On failure, we only expect the CV to timeout. Any other error value means
// that we've unexpectedly woken up.
// Note that WAIT_TIMEOUT != ERROR_TIMEOUT. WAIT_TIMEOUT is used with the
Expand All @@ -51,11 +55,11 @@ void ConditionVariable::TimedWait(const TimeDelta& max_time) {
}

void ConditionVariable::Broadcast() {
WakeAllConditionVariable(&cv_);
WakeAllConditionVariable(reinterpret_cast<PCONDITION_VARIABLE>(&cv_));
}

void ConditionVariable::Signal() {
WakeConditionVariable(&cv_);
WakeConditionVariable(reinterpret_cast<PCONDITION_VARIABLE>(&cv_));
}

} // namespace base
6 changes: 3 additions & 3 deletions base/synchronization/lock_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "build/build_config.h"

#if defined(OS_WIN)
#include <windows.h>
#include "base/win/windows_types.h"
#elif defined(OS_POSIX)
#include <errno.h>
#include <pthread.h>
Expand All @@ -26,7 +26,7 @@ namespace internal {
class BASE_EXPORT LockImpl {
public:
#if defined(OS_WIN)
using NativeHandle = SRWLOCK;
using NativeHandle = CHROME_SRWLOCK;
#elif defined(OS_POSIX)
using NativeHandle = pthread_mutex_t;
#endif
Expand Down Expand Up @@ -63,7 +63,7 @@ class BASE_EXPORT LockImpl {

#if defined(OS_WIN)
void LockImpl::Unlock() {
::ReleaseSRWLockExclusive(&native_handle_);
::ReleaseSRWLockExclusive(reinterpret_cast<PSRWLOCK>(&native_handle_));
}
#elif defined(OS_POSIX)
void LockImpl::Unlock() {
Expand Down
7 changes: 5 additions & 2 deletions base/synchronization/lock_impl_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#include "base/debug/activity_tracker.h"

#include <windows.h>

namespace base {
namespace internal {

Expand All @@ -14,7 +16,8 @@ LockImpl::LockImpl() : native_handle_(SRWLOCK_INIT) {}
LockImpl::~LockImpl() = default;

bool LockImpl::Try() {
return !!::TryAcquireSRWLockExclusive(&native_handle_);
return !!::TryAcquireSRWLockExclusive(
reinterpret_cast<PSRWLOCK>(&native_handle_));
}

void LockImpl::Lock() {
Expand All @@ -30,7 +33,7 @@ void LockImpl::Lock() {
return;

base::debug::ScopedLockAcquireActivity lock_activity(this);
::AcquireSRWLockExclusive(&native_handle_);
::AcquireSRWLockExclusive(reinterpret_cast<PSRWLOCK>(&native_handle_));
}

} // namespace internal
Expand Down
2 changes: 2 additions & 0 deletions base/synchronization/waitable_event_watcher_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include "base/synchronization/waitable_event.h"
#include "base/win/object_watcher.h"

#include <windows.h>

namespace base {

WaitableEventWatcher::WaitableEventWatcher() = default;
Expand Down
1 change: 1 addition & 0 deletions base/syslog_logging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "base/syslog_logging.h"

#if defined(OS_WIN)
#include <windows.h>
#include "base/bind.h"
#include "base/callback_helpers.h"
#include "base/debug/stack_trace.h"
Expand Down
2 changes: 2 additions & 0 deletions base/test/test_reg_util_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include "base/strings/utf_string_conversions.h"
#include "testing/gtest/include/gtest/gtest.h"

#include <windows.h>

namespace registry_util {

namespace {
Expand Down
2 changes: 1 addition & 1 deletion base/threading/platform_thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include "build/build_config.h"

#if defined(OS_WIN)
#include <windows.h>
#include "base/win/windows_types.h"
#elif defined(OS_MACOSX)
#include <mach/mach_types.h>
#elif defined(OS_FUCHSIA)
Expand Down
2 changes: 2 additions & 0 deletions base/threading/platform_thread_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#include "base/threading/thread_restrictions.h"
#include "base/win/scoped_handle.h"

#include <windows.h>

namespace base {

namespace {
Expand Down
2 changes: 1 addition & 1 deletion base/threading/thread_local_storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "build/build_config.h"

#if defined(OS_WIN)
#include <windows.h>
#include "base/win/windows_types.h"
#elif defined(OS_POSIX)
#include <pthread.h>
#endif
Expand Down
Loading

0 comments on commit bfdc3fd

Please sign in to comment.