Commit Graph

3058 Commits

Author SHA1 Message Date
Abseil Team
03cc841ff0 Use non-stack storage for stack trace buffers
Doing this opportunistically allows us to avoid performance overhead in the vast majority of calls (rare, non-reentrant ones) while simultaneously minimizing stack space usage.

PiperOrigin-RevId: 831560881
Change-Id: Idc6ba1dd0dcf1b4aaf3ee7cf468054bcfdcf90af
2025-11-12 15:23:29 -08:00
Abseil Team
e6a6acdca4 Fixed incorrect include for ABSL_NAMESPACE_BEGIN
PiperOrigin-RevId: 831364966
Change-Id: Ib2b3346523ffa1627899b1d6df55e3a9d9c41260
2025-11-12 06:40:49 -08:00
Derek Mauro
9abb0b5196 Add ABSL_REFACTOR_INLINE to separate the inliner directive from the
deprecated directive so that we can give users a custom deprecation
message.

PiperOrigin-RevId: 830908658
Change-Id: I07fec685b025ea507ef7dd16f117d4c29e80a2c1
2025-11-11 07:39:06 -08:00
Abseil Team
c70fe97137 Reduce stack usage when unwinding without fixups
The existing code uses the same stack space regardless of whether fixups are performed. This commit avoids using the stack space in calls that statically bypass fixups, to reduce the potential of a stack overflow.

PiperOrigin-RevId: 830610605
Change-Id: I06168e44e7199e10a606ff634e214ac9a8f9b872
2025-11-10 14:53:12 -08:00
Abseil Team
29d24c5fd3 Reduce stack usage when unwinding from 170 to 128 on x64
PiperOrigin-RevId: 830569454
Change-Id: If5f56cc64ad1f3fe2de45c273b2567ba6ebfe9ed
2025-11-10 13:09:52 -08:00
Chris Kennelly
ff43958956 Rename RecordInsert -> RecordInsertMiss.
This is to distinguish it from insert operations that find an existing value.

PiperOrigin-RevId: 828654839
Change-Id: I7ef1ffef22e978d806932537962292f81526521f
2025-11-05 15:31:12 -08:00
Mark Rowe
0f89191097 PR #1968: Use std::move_backward within InlinedVector's Storage::Insert
Imported from GitHub PR https://github.com/abseil/abseil-cpp/pull/1968

Both libc++ and libstdc++ have optimizations within `std::move_backward` that support lowering to `memmove` when it is appropriate for the types involved. Using it significantly speeds up insert on vectors of trivial types such as integers.

This completely addresses the [poor insert performance relative to other inline capacity vectors](https://github.com/martinus/svector#random-insert) that others have observed. See also https://github.com/abseil/abseil-cpp/discussions/1934.
Merge 8ce6a5e699 into 7374f9b0f4

Merging this change closes #1968

COPYBARA_INTEGRATE_REVIEW=https://github.com/abseil/abseil-cpp/pull/1968 from bdash:inlinedvector-insert-move 8ce6a5e699
PiperOrigin-RevId: 828597732
Change-Id: Ica73f189f3fd5385ee90b532964ddf476d3fa223
2025-11-05 13:11:08 -08:00
Derek Mauro
d6f45774b7 Use the new absl::StringResizeAndOverwrite() in CUnescape()
PiperOrigin-RevId: 828537473
Change-Id: I7f77f26c7f1495f9764a748a82dfc7e2753da0fb
2025-11-05 10:45:42 -08:00
Vitaly Goldshteyn
f328effd5d Explicitly instantiate common raw_hash_set backing array functions.
Add explicit template instantiations for `AllocateBackingArray` and `DeallocateBackingArray` in `raw_hash_set.cc` for the `std::allocator<char>` and `alignof(size_t)` case. Add corresponding `extern template` declarations in `raw_hash_set.h`. This reduces compile times and linker input size by ensuring these common instantiations are only generated once.

PiperOrigin-RevId: 828501019
Change-Id: I2927e756f0cf8238d6455c6eee4473fff790435f
2025-11-05 09:22:27 -08:00
Vitaly Goldshteyn
5bd1257b98 Rollback reduction of maximum load factor. Now it is back to 28/32.
There was no visible improvement and potentially performance regression in the production.

PiperOrigin-RevId: 828365574
Change-Id: Id3dab84ce9a6a6c132db40f370303fee0a42ed9b
2025-11-05 02:00:40 -08:00
Abseil Team
18ac608307 Export Mutex::Dtor from shared libraries in NDEBUG mode
When Abseil is built as a shared library (`ABSL_BUILD_DLL`) with `NDEBUG` defined, `Mutex::Dtor()` is currently fully inlined and no symbol is emitted.

Downstream clients building against this shared library without `NDEBUG` defined (e.g., a debug build of an application linking against a system-provided release Abseil DLL) will expect a `Mutex::Dtor()` symbol to exist, ensuring ABI compatibility. Currently, this leads to undefined reference linker errors.

This patch aligns `Mutex::Dtor()` with the existing logic for `Mutex::~Mutex()`: it disables inlining in the header when `ABSL_BUILD_DLL` is active and ensures an empty definition is provided in the source file for these builds.

PiperOrigin-RevId: 828160210
Change-Id: I5ed1fd6757d631e80d6f084d20bfe8e25f6ef253
2025-11-04 15:33:27 -08:00
Zie Weaver
6d94b2ce15 Allow IsOkAndHolds to rely on duck typing for matching StatusOr like types
instead of uniquely `absl::StatusOr`, e.g. `google::cloud::StatusOr`.

This is intended to support existing types that provide compliant `.ok()` and
`.status()`.  However support for types other than absl::StatusOr is not a
guaranteed feature and may be removed in the future

PiperOrigin-RevId: 828072487
Change-Id: I1ae696b41eecf6048bd7a4ae3d893648e57e81d1
2025-11-04 11:52:55 -08:00
Abseil Team
7374f9b0f4 Fix typo in macro and add missing static_cast for WASM builds.
Corrects `__asjms__` to `__asmjs__` and adds a `static_cast<size_t>` to the result of `getpagesize() - 1`.

Without this static cast, emscripten based builds will trigger `-Wsign-conversion` on this line.

PiperOrigin-RevId: 827655583
Change-Id: I19b8ed7d3240409127934ac6debcb523fdb73e22
2025-11-03 14:40:09 -08:00
Corentin Le Molgat
d1ddbf4d21 windows(cmake): add abseil_test_dll to target link libraries when required
Fix #1967

PiperOrigin-RevId: 827621016
Change-Id: I0ba2b2259851cce99cd719c1daeb4ada528baa93
2025-11-03 13:12:04 -08:00
Abseil Team
cd62ba571c Handle empty strings in SimpleAtof after stripping whitespace
Add an explicit check for an empty string after `StripAsciiWhitespace` in `SimpleAtof` to avoid issues with `absl::from_chars`, which does not accept empty input.

PiperOrigin-RevId: 827589429
Change-Id: Iaf7e486d40d2c981a070aab912c7c61b72b33553
2025-11-03 11:49:08 -08:00
Derek Mauro
b13bf1d129 Avoid using a thread_local in an inline function since this
causes issues on some platforms.

Fixes #1946

PiperOrigin-RevId: 827571630
Change-Id: I217acb5778fa1224422e4893cc71c896e2c795fa
2025-11-03 11:06:02 -08:00
Connal de Souza
982f4254a1 (Roll forward) Change Abseil's SpinLock adaptive_spin_count to a class static variable that can be set by tcmalloc friend classes.
PiperOrigin-RevId: 826545231
Change-Id: Ic8918fdc0ebd46ea0423859ed62d667f7fe0ba57
2025-10-31 10:40:46 -07:00
Abseil Team
6c5a175774 Change Abseil's SpinLock adaptive_spin_count to a class static variable that can be set by tcmalloc friend classes.
PiperOrigin-RevId: 826261810
Change-Id: I48eedaf091aff3d9c6b97b7eb8c71958711348cf
2025-10-30 18:12:37 -07:00
Connal de Souza
ed0efc0037 Change Abseil's SpinLock adaptive_spin_count to a class static variable that can be set by tcmalloc friend classes.
PiperOrigin-RevId: 826226544
Change-Id: I8f8cb5ce199eab9ca63fcd475b536f4a1f512a19
2025-10-30 16:13:20 -07:00
Derek Mauro
f43bcc04d9 Fixes for String{Resize|Append}AndOverwrite
- StringAppendAndOverwrite() should always call StringResizeAndOverwrite()
    with at least capacity() in case the standard library decides to shrink
    the buffer (Fixes #1965)
  - Small refactor to make the minimum growth an addition for clarity and
    to make it easier to test 1.5x growth in the future
  - Turn an ABSL_HARDENING_ASSERT into a ThrowStdLengthError
  - Add a missing std::move

PiperOrigin-RevId: 826107106
Change-Id: I73ee3e98daa10161aa9023b2a879f6178ebedbcf
2025-10-30 11:06:09 -07:00
Zie Weaver
01a4ea7fbb Correct the supported features of Status Matchers
PiperOrigin-RevId: 825711552
Change-Id: Ie0983c7decdcd5e1aee628a0ceef3ee76bc7cb17
2025-10-29 14:34:06 -07:00
Abseil Team
aed1a5e5f7 absl/time: Use "memory order acquire" for loads, which would allow for the safe removal of the data memory barrier.
PiperOrigin-RevId: 825322666
Change-Id: Ic47304c6914f3e5dae45682b6c2304f3dc7ad1b1
2025-10-28 20:03:19 -07:00
Derek Mauro
9a2624f3e7 Use the new absl::StringResizeAndOverwrite() in string escaping utilities
PiperOrigin-RevId: 825168879
Change-Id: I5dfcd546ffe01fc2035f4380c92ffd9afaa52331
2025-10-28 13:00:59 -07:00
Derek Mauro
f81f1b1d08 Add an internal-only helper StringAppendAndOverwrite() similar to
StringResizeAndOverwrite() but optimized for repeated appends, using
exponential growth to ensure amortized complexity of increasing
a string size by a small amount is O(1).

Use this function to replace STLStringResizeUninitializedAmortized()

PiperOrigin-RevId: 825100704
Change-Id: Ife64b13301bc4288d68154b7c496f57aaad4b6a4
2025-10-28 10:26:25 -07:00
Zie Weaver
2487de0742 Release ABSL_EXPECT_OK and ABSL_ASSERT_OK.
These are convenience macros for `EXPECT_THAT(..., IsOk())` and
`ASSERT_THAT(..., IsOk())`, which can sometimes be more convenient to write.

This also documents a `#define` flag that defines the unqualified (i.e.
`EXPECT_OK` and `ASSERT_OK` versions of these macros, though they're
not preferred.

PiperOrigin-RevId: 825052892
Change-Id: Ib699709fbda3bc4885f57fc2842fb852c6243a2f
2025-10-28 08:31:41 -07:00
Samuel Benzaquen
f0a99676ff Fix the CHECK_XX family of macros to not print char* arguments as C-strings if the comparison happened as pointers.
Printing as pointers is more relevant to the result of the comparison.

PiperOrigin-RevId: 824656335
Change-Id: I3b586e633c1271c1728c961193db106e4f4e5a8b
2025-10-27 13:35:03 -07:00
Derek Mauro
b8c46feecc Rollback StringAppendAndOverwrite() - the problem is that
StringResizeAndOverwrite has MSAN testing of the entire string.
This causes quadratic MSAN verification on small appends.

PiperOrigin-RevId: 824629932
Change-Id: Ibefff781f5923c8bd2c1dc364f5b63fcb1d0f5ab
2025-10-27 12:30:02 -07:00
Derek Mauro
d3c55ba366 Add an internal-only helper StringAppendAndOverwrite() similar to
StringResizeAndOverwrite() but optimized for repeated appends, using
exponential growth to ensure amortized complexity of increasing
a string size by a small amount is O(1).

Use this function to replace STLStringResizeUninitializedAmortized()

PiperOrigin-RevId: 824571998
Change-Id: I6fe4a9cadd469ceee6a3818d7b8709e2fa286b9c
2025-10-27 10:16:39 -07:00
Milad Fa
1a259163cc PR #1961: Fix Clang warnings on powerpc
Imported from GitHub PR https://github.com/abseil/abseil-cpp/pull/1961

We maintain the V8 Js Compiler on IBM platforms which uses abseil as a dependency. We have recently switched to using Clang and need to create this patch to fix two warnings:
```
warning: implicit conversion changes signedness: 'uint64_t' (aka 'unsigned long') to 'int64_t' (aka 'long') [-Wsign-conversion]
warning: implicit conversion loses integer precision: 'uintptr_t' (aka 'unsigned long') to 'int' [-Wshorten-64-to-32]
```
Merge 2e972b5c72 into d71fcd13f6

Merging this change closes #1961

COPYBARA_INTEGRATE_REVIEW=https://github.com/abseil/abseil-cpp/pull/1961 from miladfarca:ppc-fix-clang-warn 2e972b5c72
PiperOrigin-RevId: 823581713
Change-Id: Icff10b99b3808f51866fb97576af405826742088
2025-10-24 10:30:43 -07:00
Abseil Team
d71fcd13f6 Use the new absl::StringResizeAndOverwrite() in string escaping utilities
PiperOrigin-RevId: 823263060
Change-Id: Ife62660889ce8602013ccbb563ec853ae22fee9f
2025-10-23 18:08:57 -07:00
Derek Mauro
09c29fe055 Use the new absl::StringResizeAndOverwrite() in string escaping utilities
PiperOrigin-RevId: 823159114
Change-Id: I94ccf42464a5fee6233b15dc8d44503b0b3f9db2
2025-10-23 13:10:11 -07:00
Derek Mauro
4099f7429a macOS CI: Move the Bazel vendor_dir to ${HOME} to workaround a Bazel issue
where it does not work when it is in ${TMP} and also fix the quoting
which was causing it to incorrectly receive the argument

https://github.com/bazelbuild/bazel/issues/27156

PiperOrigin-RevId: 823141075
Change-Id: I465f6bda0d94f4e464fa7ce3c1ee019aec78db69
2025-10-23 12:18:14 -07:00
Abseil Team
ee47800225 Use __msan_check_mem_is_initialized for detailed MSan report
This replaces the __msan_test_shadow introduced in "Validate absl::StringResizeAndOverwrite op has written bytes as expected." with __msan_check_mem_is_initialized, because the __msan_test_shadow assertion gives terse output ("false && shadow == -1") and cannot benefit from MSan's track origins mode.

PiperOrigin-RevId: 822786851
Change-Id: I8927521b5c38a7491f3b4e77e479014bba75cb36
2025-10-22 16:42:42 -07:00
Abseil Team
f40a1cce40 Optimize stack unwinding by reducing AddressIsReadable calls.
PiperOrigin-RevId: 822738922
Change-Id: Ifd784d16ffb8ae810900b11e41a74ac1f263ed89
2025-10-22 14:22:01 -07:00
Abseil Team
6cdb3d1b38 Add internal API to allow bypassing stack trace fixups when needed
PiperOrigin-RevId: 822668786
Change-Id: I72d6178bbbde8b05b529e2d8297772cbb63758d0
2025-10-22 11:24:12 -07:00
Abseil Team
04e19d0731 absl::StrFormat: improve test coverage with scientific exponent test cases
PiperOrigin-RevId: 822611844
Change-Id: Idc5af6835868ac7336e945ecc29d5b83d1325e09
2025-10-22 09:03:14 -07:00
Shahriar Rouf
215d8a0e75 Add throughput and latency benchmarks for absl::ToDoubleXYZ functions.
Sample benchmark result on a Skylake machine:
```
name                                       time/op
BM_Duration_ToInt64Nanoseconds             1.506n ± 0%
BM_Duration_ToInt64Microseconds            1.499n ± 1%
BM_Duration_ToInt64Milliseconds            1.502n ± 1%
BM_Duration_ToInt64Seconds                 1.498n ± 1%
BM_Duration_ToInt64Minutes                 1.495n ± 1%
BM_Duration_ToInt64Hours                   1.502n ± 1%
BM_Duration_ToDoubleNanoseconds            1.589n ± 1%
BM_Duration_ToDoubleMicroseconds           1.712n ± 1%
BM_Duration_ToDoubleMilliseconds           1.712n ± 1%
BM_Duration_ToDoubleSeconds                1.715n ± 1%
BM_Duration_ToDoubleMinutes                1.716n ± 1%
BM_Duration_ToDoubleHours                  1.717n ± 1%
BM_Duration_ToDoubleNanoseconds_Latency    9.934n ± 1%
BM_Duration_ToDoubleMicroseconds_Latency   13.08n ± 0%
BM_Duration_ToDoubleMilliseconds_Latency   13.06n ± 0%
BM_Duration_ToDoubleSeconds_Latency        13.06n ± 1%
BM_Duration_ToDoubleMinutes_Latency        13.01n ± 1%
BM_Duration_ToDoubleHours_Latency          13.03n ± 1%
BM_Duration_ToTimespec_AbslTime            1.567n ± 1%
BM_Duration_ToTimespec_Double              1.282n ± 1%
geomean                                    2.920n
```

PiperOrigin-RevId: 822317999
Change-Id: I0055d0780c9039ee30be52bc284599a3bcb24f56
2025-10-21 16:20:25 -07:00
Derek Mauro
f807de027a CordzInfo: Use absl::NoDestructor to remove a global destructor.
Chromium requires no global destructors.

PiperOrigin-RevId: 822156140
Change-Id: Ieedc7e042df035e000649a2f07a217dee6ca40e7
2025-10-21 09:40:32 -07:00
Jesse Rosenstock
71c513c5f8 string_view: Enable std::view and std::borrowed_range
These are enabled for `std::string_view`.

https://en.cppreference.com/w/cpp/string/basic_string_view.html#Helper_templates

PiperOrigin-RevId: 822117252
Change-Id: I8b503a0612d33eabf1be3550c0ea735866c28d63
2025-10-21 07:56:05 -07:00
Andy Getzendanner
2f1be7bdae cleanup: s/logging_internal/log_internal/ig for consistency
PiperOrigin-RevId: 822103413
Change-Id: I500f098847906439b869b2eb34c98abba10b10ea
2025-10-21 07:12:57 -07:00
Abseil Team
8faaaebc12 Use the new absl::StringResizeAndOverwrite() in string escaping utilities
PiperOrigin-RevId: 821867896
Change-Id: I6fe8456d8081ad87c8512dff6fc9235ab73e9448
2025-10-20 17:16:32 -07:00
Derek Mauro
c9ffd888c1 Use the new absl::StringResizeAndOverwrite() in string escaping utilities
PiperOrigin-RevId: 821767972
Change-Id: Ia4d38b49bc97a485dec3e352dcb056ca1c4465d6
2025-10-20 13:02:08 -07:00
Derek Mauro
1f659deb71 Use the new absl::StringResizeAndOverwrite() in absl::AsciiStrTo{Lower|Upper}
PiperOrigin-RevId: 821741205
Change-Id: I428c416429e6a6ca0ed769f0ab9487b40acc7999
2025-10-20 11:58:29 -07:00
Derek Mauro
4dbcee4b9e Use the new absl::StringResizeAndOverwrite() in absl::StrJoin()
PiperOrigin-RevId: 821692002
Change-Id: I47d1e8ef24fdef314f96eb28f5d36d098570d0e6
2025-10-20 10:00:25 -07:00
Derek Mauro
bda5c03b3c Use the new absl::StringResizeAndOverwrite() in absl::StrCat()
PiperOrigin-RevId: 821664382
Change-Id: I864eabd832c3e09b13373356b09954e1f2cc038c
2025-10-20 08:45:20 -07:00
Jesse Rosenstock
fdb6e72c75 string_view: Fix include order
PiperOrigin-RevId: 821635144
Change-Id: I5e3e8457482c926aabf9ee016f28956f05064ed0
2025-10-20 07:14:20 -07:00
Abseil Team
0d9dff74c9 Don't pass nullptr as the 1st arg of from_chars
`from_chars` marks them as `nonnull`, and this is
the case for empty string.

Existing `from_chars` implementation returns
`invalid_argument` which results in `return false`
from `SimpleAtod`.

PiperOrigin-RevId: 820759784
Change-Id: I6635e4eaf339eb178d32f616189f7733808019f5
2025-10-17 11:09:27 -07:00
Aaron Jacobs
ab4f684de4 absl/types: format code with clang-format.
PiperOrigin-RevId: 820434760
Change-Id: I70e5e4b6a433137e55d4ec27be04f6acd46ad649
2025-10-16 16:14:40 -07:00
Chris Kennelly
d6c9f93ab6 Validate absl::StringResizeAndOverwrite op has written bytes as expected.
PiperOrigin-RevId: 820383934
Change-Id: I45be1c15cd2080772cea9bfe267041be5b530832
2025-10-16 14:00:31 -07:00
Evan Brown
6725fe31f5 Skip the ShortStringCollision test on WASM.
We see collisions due to no ASLR and 32-bit size_t.

PiperOrigin-RevId: 820276001
Change-Id: I6f3e0d8ade2152fed9759285b7f92a133c6bff14
2025-10-16 09:48:32 -07:00