Skip to content

Commit 9c5e8c5

Browse files
committed
[CMake] Optimize bmalloc and FastMalloc.cpp in Debug builds
https://bugs.webkit.org/show_bug.cgi?id=328481 Reviewed by Nikolas Zimmermann and Ian Grunert. Debug builds compile bmalloc, and FastMalloc.cpp, which inlines the libpas allocation fast paths, at -O0, so every allocation in a Debug build runs unoptimized allocator code. 322547@main added -O3 for both on Cocoa; move the rules to the shared CMake files so that every CMake port gets them. Windows is left out because clang-cl ignores -O3. FastMalloc.cpp also skips the precompiled header, since clang rejects a PCH built at -O0 from an -O3 compile. An A/B comparison on a WPE Debug build ran 4989 layout tests from fast/dom, fast/css, js/dom, imported/w3c/web-platform-tests/dom, editing/execCommand and media/modern-media-controls with 16 workers, twice per variant: before after run 1 wall time 814s 583s run 2 wall time 803s 609s All tests ran as expected in every run, and the sum of the per-test times dropped by 27%. editing/execCommand/delete-non-editable-range-crash.html, which timed out after 60s in Debug, now passes in under a second, so its expectation is removed. The cost is detail in the allocator frames of Debug crash logs. Faults injected into fastFree() and fastMalloc() were compared using the gdb command the bots run on core dumps. All frames from the allocator's caller outward are identical. WTF::fastMalloc(), WTF::fastFree() and the bmalloc::api wrappers no longer appear because they become tail calls, and most libpas frames between them and the panic disappear: an invalid free goes from 13 allocator frames to 4 and an allocation failure from 9 to 5. Some allocator locals print as <optimized out>. The panic message, the faulting pointer and the requested size are still reported. * LayoutTests/platform/glib/TestExpectations: * Source/WTF/wtf/CMakeLists.txt: * Source/WTF/wtf/PlatformCocoa.cmake: * Source/bmalloc/CMakeLists.txt: * Source/bmalloc/PlatformCocoa.cmake: Canonical link: https://commits.webkit.org/324626@main
1 parent a0ab42e commit 9c5e8c5

5 files changed

Lines changed: 11 additions & 10 deletions

File tree

‎LayoutTests/platform/glib/TestExpectations‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1669,7 +1669,6 @@ editing/input/compositionend-data-after-aborting-composition.html [ Failure ]
16691669
webkit.org/b/286128 [ Release ] editing/inserting/insert-list-user-select-none-crash.html [ Crash Pass Timeout ]
16701670

16711671
webkit.org/b/179261 editing/selection/drag-to-contenteditable-iframe.html [ Timeout ]
1672-
[ Debug ] editing/execCommand/delete-non-editable-range-crash.html [ Timeout Pass ]
16731672

16741673
webkit.org/b/312533 editing/selection/first-letter-selection-painting.html [ ImageOnlyFailure Pass ]
16751674

‎Source/WTF/wtf/CMakeLists.txt‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -853,6 +853,12 @@ if (NOT APPLE AND SWIFT_REQUIRED)
853853
file(WRITE "${WTF_HEADERS_DIR}/ios/WebCoreThread.h" "")
854854
endif ()
855855

856+
if (NOT MSVC)
857+
set_source_files_properties(FastMalloc.cpp PROPERTIES
858+
COMPILE_OPTIONS $<$<CONFIG:Debug>:-O3>
859+
SKIP_PRECOMPILE_HEADERS ON)
860+
endif ()
861+
856862
WEBKIT_FRAMEWORK(WTF)
857863

858864
# WTF is statically linked into JavaScriptCore, so it uses JSC's PGO profile.

‎Source/WTF/wtf/PlatformCocoa.cmake‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,4 @@ endif ()
181181
# OBJCXX precompiled header is built with the same flag as the sources that use it.
182182
target_compile_options(WTF PRIVATE $<$<COMPILE_LANGUAGE:OBJC,OBJCXX>:-fobjc-arc>)
183183

184-
# Optimize the inlined bmalloc fast paths even in Debug builds. The prefix
185-
# header's PCH is built without optimization, so it can't be used here.
186-
# Aside from developer UX benefit, needed to prevent tests from timing out.
187-
set_source_files_properties(FastMalloc.cpp PROPERTIES
188-
COMPILE_OPTIONS -O3
189-
SKIP_PRECOMPILE_HEADERS ON)
190-
191184
WEBKIT_ADD_PREFIX_HEADER(WTF WTFPrefix.h PREFIX_LANGUAGES CXX OBJCXX PREFIX_NO_CODEGEN)

‎Source/bmalloc/CMakeLists.txt‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,10 @@ set(bmalloc_COMPILE_OPTIONS
673673
-Wno-missing-field-initializers
674674
)
675675

676+
if (NOT MSVC)
677+
list(APPEND bmalloc_COMPILE_OPTIONS $<$<CONFIG:Debug>:-O3>)
678+
endif ()
679+
676680
set(bmalloc_INTERFACE_LIBRARIES bmalloc)
677681
set(bmalloc_INTERFACE_INCLUDE_DIRECTORIES ${bmalloc_FRAMEWORK_HEADERS_DIR})
678682
set(bmalloc_INTERFACE_DEPENDENCIES bmalloc_CopyHeaders)

‎Source/bmalloc/PlatformCocoa.cmake‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,4 @@ list(APPEND bmalloc_SOURCES
1111
find_library(FOUNDATION_LIBRARY Foundation)
1212
list(APPEND bmalloc_LIBRARIES ${FOUNDATION_LIBRARY})
1313

14-
# Optimize bmalloc even in Debug builds.
15-
target_compile_options(bmalloc PRIVATE -O3 -fno-threadsafe-statics)
14+
target_compile_options(bmalloc PRIVATE -fno-threadsafe-statics)

0 commit comments

Comments
 (0)