From 1aa7f17b566753c4996b425a24270547f7a157ea Mon Sep 17 00:00:00 2001 From: Ryan Macnak Date: Tue, 24 Jan 2023 00:54:29 +0000 Subject: [PATCH] [build] Default to -O2 instead of -O3. This moderately reduces code size without large regressions on Golem. Going further to -Os still produces noticeable regressions. TEST=ci Bug: https://github.com/dart-lang/sdk/issues/38647 Change-Id: I8409908ca37d4a2b18cb989d9748e35a15072df6 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/217504 Reviewed-by: Siva Annamalai Commit-Queue: Ryan Macnak --- build/config/compiler/BUILD.gn | 6 +---- runtime/BUILD.gn | 2 +- runtime/lib/typed_data.cc | 24 +++++++++++++----- runtime/vm/object.h | 45 ---------------------------------- 4 files changed, 20 insertions(+), 57 deletions(-) diff --git a/build/config/compiler/BUILD.gn b/build/config/compiler/BUILD.gn index 1f919ca7ec9..feb13b1af62 100644 --- a/build/config/compiler/BUILD.gn +++ b/build/config/compiler/BUILD.gn @@ -815,13 +815,9 @@ if (is_win) { # Default "optimization on" config. On Windows, this favors size over speed. config("optimize") { if (is_win) { - # Favor size over speed, /O1 must be before the common flags. The GYP - # build also specifies /Os and /GF but these are implied by /O1. cflags = [ "/O2" ] + common_optimize_on_cflags + [ "/Oi" ] - } else if (is_android) { - cflags = [ "-Os" ] + common_optimize_on_cflags # Favor size over speed. } else { - cflags = [ "-O3" ] + common_optimize_on_cflags + cflags = [ "-O2" ] + common_optimize_on_cflags } ldflags = common_optimize_on_ldflags } diff --git a/runtime/BUILD.gn b/runtime/BUILD.gn index 47e96213e42..2b8f56010ed 100644 --- a/runtime/BUILD.gn +++ b/runtime/BUILD.gn @@ -245,7 +245,7 @@ config("dart_config") { } else if (dart_debug) { cflags += [ "-O${dart_debug_optimization_level}" ] } else { - cflags += [ "-O3" ] + cflags += [ "-O2" ] } if (is_fuchsia) { diff --git a/runtime/lib/typed_data.cc b/runtime/lib/typed_data.cc index e4d51d70906..d16b345bf4e 100644 --- a/runtime/lib/typed_data.cc +++ b/runtime/lib/typed_data.cc @@ -79,12 +79,24 @@ static BoolPtr CopyData(const TypedDataBase& dst_array, src_array.LengthInBytes())); ASSERT(Utils::RangeCheck(dst_offset_in_bytes, length_in_bytes, dst_array.LengthInBytes())); - if (clamped) { - TypedData::ClampedCopy(dst_array, dst_offset_in_bytes, src_array, - src_offset_in_bytes, length_in_bytes); - } else { - TypedData::Copy(dst_array, dst_offset_in_bytes, src_array, - src_offset_in_bytes, length_in_bytes); + if (length_in_bytes > 0) { + NoSafepointScope no_safepoint; + if (clamped) { + uint8_t* dst_data = + reinterpret_cast(dst_array.DataAddr(dst_offset_in_bytes)); + int8_t* src_data = + reinterpret_cast(src_array.DataAddr(src_offset_in_bytes)); + for (intptr_t ix = 0; ix < length_in_bytes; ix++) { + int8_t v = *src_data; + if (v < 0) v = 0; + *dst_data = v; + src_data++; + dst_data++; + } + } else { + memmove(dst_array.DataAddr(dst_offset_in_bytes), + src_array.DataAddr(src_offset_in_bytes), length_in_bytes); + } } return Bool::True().ptr(); } diff --git a/runtime/vm/object.h b/runtime/vm/object.h index 6138ecb11a8..67e88afb139 100644 --- a/runtime/vm/object.h +++ b/runtime/vm/object.h @@ -11431,51 +11431,6 @@ class TypedData : public TypedDataBase { intptr_t len, Heap::Space space = Heap::kNew); - static void Copy(const TypedDataBase& dst, - intptr_t dst_offset_in_bytes, - const TypedDataBase& src, - intptr_t src_offset_in_bytes, - intptr_t length_in_bytes) { - ASSERT(Utils::RangeCheck(src_offset_in_bytes, length_in_bytes, - src.LengthInBytes())); - ASSERT(Utils::RangeCheck(dst_offset_in_bytes, length_in_bytes, - dst.LengthInBytes())); - { - NoSafepointScope no_safepoint; - if (length_in_bytes > 0) { - memmove(dst.DataAddr(dst_offset_in_bytes), - src.DataAddr(src_offset_in_bytes), length_in_bytes); - } - } - } - - static void ClampedCopy(const TypedDataBase& dst, - intptr_t dst_offset_in_bytes, - const TypedDataBase& src, - intptr_t src_offset_in_bytes, - intptr_t length_in_bytes) { - ASSERT(Utils::RangeCheck(src_offset_in_bytes, length_in_bytes, - src.LengthInBytes())); - ASSERT(Utils::RangeCheck(dst_offset_in_bytes, length_in_bytes, - dst.LengthInBytes())); - { - NoSafepointScope no_safepoint; - if (length_in_bytes > 0) { - uint8_t* dst_data = - reinterpret_cast(dst.DataAddr(dst_offset_in_bytes)); - int8_t* src_data = - reinterpret_cast(src.DataAddr(src_offset_in_bytes)); - for (intptr_t ix = 0; ix < length_in_bytes; ix++) { - int8_t v = *src_data; - if (v < 0) v = 0; - *dst_data = v; - src_data++; - dst_data++; - } - } - } - } - static bool IsTypedData(const Instance& obj) { ASSERT(!obj.IsNull()); intptr_t cid = obj.ptr()->GetClassId();