1. 10 Oct, 2024 2 commits
  2. 08 Oct, 2024 1 commit
  3. 02 Oct, 2024 2 commits
    • Improve ABSL_ASSERT performance by guaranteeing it is optimized away under NDEBUG in C++20 · 03b8d6ea
      Also fix the old definition by verifying that the condition is contextually convertible to bool.
      
      The new C++20 definition reduces codegen bloat and guarantees fast performance while still retaining the expression (so that unused-variable warnings don't trigger).
      
      As an example where this makes a difference, compare the following snippet under `-DABSL_INTERNAL_CPLUSPLUS_LANG=202002`: https://godbolt.org/z/hjf59n84v
      ```
      #include <stdlib.h>
      template<class T> struct S { S() { abort(); } static S const s; };
      template<class T> S<T> const S<T>::s = {};
      #if ABSL_INTERNAL_CPLUSPLUS_LANG >= 202002L
      #define ABSL_ASSERT(expr) (decltype((expr) ? void() : void())())
      #else
      #define ABSL_ASSERT(expr) (false ? ((expr) ? void() : void()) : void())
      #endif
      void foo() { ABSL_ASSERT(((void)&S<int>::s, true)); }
      ```
      
      We see that, in unoptimized builds, code is still generated with the old definition of `ABSL_ASSERT`. Moreover, even under optimizations (with `-O2`), the call to abort() still lingers with the old definition of `ABSL_ASSERT`.
      
      Therefore the extra generated code can affect both compile- and run-time performance.
      
      PiperOrigin-RevId: 681563573
      Change-Id: I7fbfadcc7fd198e8e1daf14615c33687f6b23af7
      Abseil Team committed
    • Mark Abseil hardening assert in AssertSameContainer as slow. · 5d347078
      When Abseil hardening is enabled, this assertion's condition gets evaluated every time an iterator equality check is performed on iterators from a raw_hash_set.  This occurs very frequently when looping over the contents of sets, due to loop conditions like `it != end()`, and causes about 0.4% CPU overhead to some Google workloads.
      
      PiperOrigin-RevId: 681560141
      Change-Id: Ia0177cbef7cf67f9f0b6adf2cf55d9a2ed320d2d
      Abseil Team committed
  4. 27 Sep, 2024 1 commit
  5. 26 Sep, 2024 1 commit
    • Small Mutex::Unlock optimization · 482ca0b9
      Saving one "&" operation in the Mutex::Unlock fast path. This has likely no performance impact (the two AND instructions ran in parallel anyway), but is as complex as the current solution, and enables two possible improvements in the future.
      
      1. If bits Ev, Wr, Wa, De are made into the highest bits in the kMuLow,
         then the second "&" operation can be omitted because if kMuWriter is set,
         the there are no readers, so the kMuHigh bits are zero.
      
      2. If the meanings of kMuWriter and kMuDesig are flipped, then the "^"
         operation is not needed either.
      
      PiperOrigin-RevId: 679272590
      Change-Id: Iea7a04df0118d2410b7bfdab70b30e33d4b90e43
      piotrzielinski committed
  6. 24 Sep, 2024 1 commit
    • Optimize `CEscape` and `CEscapeAndAppend` by up to 40%. · ba5fd097
      - Compute the escape character values at compile time.
      - Use `little_endian::Store32` invariably to write all escaped characters.
      - Use 3 slop bytes at the end so that we can safely call `little_endian::Store32` at the end as well.
      
      PiperOrigin-RevId: 677995014
      Change-Id: I9d710fff48d0ce0b013e64d726960364c77ea1d7
      Shahriar Rouf committed
  7. 23 Sep, 2024 1 commit
  8. 20 Sep, 2024 1 commit
  9. 19 Sep, 2024 2 commits
    • Fix benchmarks in `escaping_benchmark.cc` by properly calling… · b3454256
      Fix benchmarks in `escaping_benchmark.cc` by properly calling `benchmark::DoNotOptimize` on both inputs and outputs and by removing the unnecessary and wrong `ABSL_RAW_CHECK` condition (`check != 0`) of `BM_ByteStringFromAscii_Fail` benchmark.
      
      Relevant comment:
      ```
      // The DoNotOptimize(...) function can be used to prevent a value or
      // expression from being optimized away by the compiler. This function is
      // intended to add little to no overhead.
      // See: http://stackoverflow.com/questions/28287064
      //
      // The specific guarantees of DoNotOptimize(x) are:
      //  1) x, and any data it transitively points to, will exist (in a register or
      //     in memory) at the current point in the program.
      //  2) The optimizer will assume that DoNotOptimize(x) could mutate x or
      //     anything it transitively points to (although it actually doesn't).
      //
      // To see this in action:
      //
      //   void BM_multiply(benchmark::State& state) {
      //     int a = 2;
      //     int b = 4;
      //     for (auto s : state) {
      //       testing::DoNotOptimize(a);
      //       testing::DoNotOptimize(b);
      //       int c = a * b;
      //       testing::DoNotOptimize(c);
      //     }
      //   }
      //   BENCHMARK(BM_multiply);
      //
      // Guarantee (2) applied to 'a' and 'b' prevents the compiler lifting the
      // multiplication outside of the loop. Guarantee (1) applied to 'c' prevents the
      // compiler from optimizing away 'c' as dead code.
      ```
      To see #1 and #2 in action, see: https://godbolt.org/z/ned1578ve
      
      PiperOrigin-RevId: 676588185
      Change-Id: I7ed3e4bed8274b54ac7877316f2d82c33d68f00f
      Shahriar Rouf committed
    • It seems like commit abc9b916 did not work as intended. · 162dc789
      PiperOrigin-RevId: 676486501
      Change-Id: I874097a85486534150ce4c2f814d20be9d8b3b1f
      Abseil Team committed
  10. 18 Sep, 2024 1 commit
    • Fix a bug in `absl::SetVLogLevel` where a less generic pattern incorrectly… · 0df56740
      Fix a bug in `absl::SetVLogLevel` where a less generic pattern incorrectly removed a more generic one.
      
      ### Example:
      
      The user passes `--vmodule=*pipeline*=10` to enable logs in files containing `"pipeline"` in their names:
      ```
      pipeline_a.cc
      pipeline_b.cc
      pipeline_c.cc
      ```
      Additionally, `pipeline_a.cc` executes `absl::SetVlogLevel("pipeline_a", 10)`.
      
      ### Expected behavior:
      
      VLOG level `10` is enabled in all files containing `"pipeline"` in their names. `absl::SetVlogLevel("pipeline_a", 10)` should not affect this, as `pipeline_a.cc` is already covered by `--vmodule=*pipeline*=10` and have the same level there.
      
      ### Actual behavior (before the CL):
      
      VLOG level `10` is enabled only in `pipeline_a.cc`. `--vmodule=*pipeline*=10` is ignored.
      
      ### Reason:
      
      `absl::SetVlogLevel` is based on `PrependVModuleLocked`. The issue lies in the following code within `PrependVModuleLocked`:
      
      ```cc
        // This is a memory optimization to avoid storing patterns that will never
        // match due to exit early semantics. Primarily optimized for our own unit
        // tests.
        get_vmodule_info().erase(
            std::remove_if(++iter, get_vmodule_info().end(),
                           [module_pattern](const VModuleInfo& info) {
                             return FNMatch(info.module_pattern, module_pattern);
                           }),
            get_vmodule_info().cend());
      ```
      
      When `absl::SetVlogLevel("pipeline_a", 10)` is executed, `get_vmodule_info()` contains `"*pipeline*"`. Therefore, `info.module_pattern` equals to `"*pipeline*"` and `module_pattern` equals to `"pipeline_a"`.
      
      Because `"pipeline_a"` matches the pattern `"*pipeline*"`, the pattern `"*pipeline*"` is erroneously erased. `get_vmodule_info()` then only contains the `"pipeline_a"` pattern.
      
      ### Solution:
      
      This CL corrects the order of the arguments in `FNMatch` to:
      ```cc
      FNMatch(module_pattern, info.module_pattern);
      ```
      
      This ensures that it correctly checks if the new pattern is more general than the previous pattern, but not vice versa.  In the example above, the new pattern `"pipeline_a"` does not match the previous `"*pipeline*"` pattern. Therefore, `get_vmodule_info()` retains both patterns in the following order: `"pipeline_a"`, `"*pipeline*"`.
      
      PiperOrigin-RevId: 675776298
      Change-Id: I9550dbd4282e66799619369894b8304856a7a777
      Alex Titov committed
  11. 17 Sep, 2024 5 commits
    • Remove the side effects between tests in vlog_is_on_test.cc · 3aa6061a
      The original version of the tests did not reset the VLOG levels between tests, which could lead to false positives. This CL fixes the issue by resetting the VLOG levels to their default values before each test.
      
      PiperOrigin-RevId: 675711787
      Change-Id: Id311ba0c00a9e929afcddc7346882487fd64ea16
      Alex Titov committed
    • Attempt to fix flaky Abseil waiter/sleep tests · abc9b916
      The existing implementation uses wall-clock time. However, wall clock can drastically differ from the internal system clock, because the system can be suspended and then resumed.
      
      We want to account for at least some kinds of suspensions that might occur during automated testing, such as VM suspension or hypervisor preemption ("steal time"). These are tricky cases, because the physical (host) CPU is still running -- just the logical (guest) virtual CPU isn't. Therefore, we need to ensure that our time measurements exclude elapsed host-only time.
      
      Unfortunately the correctness of a method depends on the nature & configuration of each VM and the guest. For example, it can depend whether RDTSC is virtualized, or on whether the host and guest support accounting for steal time. Windows, for example, appears to only support steal time measurements if the hypervisor is Hyper-V.
      
      Since this is all for the sake of testing, we use a simpler trick that we hope will work around the problem on our systems: we subtract the so-called "interrupt time bias" from the system uptime in Windows. The interrupt time bias includes sleep/hibernation time, and seems to advance during for VM suspensions as well, so it may take care of the problem.
      
      PiperOrigin-RevId: 675654840
      Change-Id: I66150b18912175fa72609d3f137e3ea4fee8fc43
      Abseil Team committed
    • Add an explicit tag for non-SOO CommonFields (removing default ctor) and add a… · 9a18cc1a
      Add an explicit tag for non-SOO CommonFields (removing default ctor) and add a small optimization for early return in AssertNotDebugCapacity.
      
      PiperOrigin-RevId: 675640181
      Change-Id: I5ab4cc6eaa0b54932ed70e42ed654f912cf1b099
      Evan Brown committed
    • Make moved-from swisstables behave the same as empty tables. Note that we may… · 857fa4fa
      Make moved-from swisstables behave the same as empty tables. Note that we may change this in the future.
      
      PiperOrigin-RevId: 675576092
      Change-Id: Ibbe1d9d2b644ce6f6182a2d197635d6a0c5327f6
      Evan Brown committed
    • Tag tests that currently fail on darwin_arm64 with "no_test_darwin_arm64" · cbf59087
      This is to prepare for continuous testing on darwin_arm64.
      
      PiperOrigin-RevId: 675532534
      Change-Id: I58e183a3b8cac9cb73f1d0d56e9d41831f02488e
      Abseil Team committed
  12. 16 Sep, 2024 4 commits
  13. 13 Sep, 2024 1 commit
  14. 12 Sep, 2024 2 commits
    • LSC: Fix null safety issues diagnosed by Clang’s `-Wnonnull` and `-Wnullability`. · f555f69b
      **Note**: These changes are generated by hand. Review with care.
      
      This CL changes the `absl_internal` implementations of `AsciiStrToLower()` /
      `AsciiStrToUpper()` to allow `src` to be null. This can, in fact, happen if the
      `string_view` passed to the public API is empty, and the implementations handle
      it correctly. I have added comments noting that `src` is allowed to be null
      iff the size is zero.
      
      `-Wnonnull` diagnoses cases where a `nullptr` literal is passed to a parameter
      annotated nonnull, or where `nullptr` is returned from a function whose return
      type is annotated nonnull.
      
      `-Wnullability` diagnoses cases where nullability annotations conflict, for
      example between the declaration and definition of a function.
      
      PiperOrigin-RevId: 673846759
      Change-Id: I6cf3490ce13837eba9814156c420598000ecc596
      Martin Brænne committed
    • Remove the extraneous variable creation in Match(). · a1a7086e
      PiperOrigin-RevId: 673830978
      Change-Id: I81e52da873dcff75d6a8502578600ec7db50f221
      Abseil Team committed
  15. 11 Sep, 2024 2 commits
    • Import of CCTZ from GitHub. · 1d4466e8
        - d1397431006ea1362a5914d4a90b265d0c7c6f2c Update zoneinfo files to 2024b (#300) by Bradley White <14679271+devbww@users.noreply.github.com>
        - 8bdbd840e97ff32e17f25db85c82589819ad3352 Fix mingw compiler error due to missing function declarat... by Biswapriyo Nath <nathbappai@gmail.com>
        - 6624659e01e73e41527d6b27036e9f79a556560f Add GitHub Actions CI (#299) by Derek Mauro <761129+derekmauro@users.noreply.github.com>
      
      PiperOrigin-RevId: 673451051
      Change-Id: Id39f2186bbdcb802d4fc4c5e21207c6f3709c56f
      Derek Mauro committed
    • Add more debug capacity validation checks on merge/swap. · 0bc0e9a0
      PiperOrigin-RevId: 673403995
      Change-Id: I62d8bb37d4538c340783fb55e5a00694e932b6d1
      Evan Brown committed
  16. 06 Sep, 2024 1 commit
  17. 05 Sep, 2024 2 commits
  18. 04 Sep, 2024 1 commit
  19. 03 Sep, 2024 1 commit
    • Remove first prefetch. · b014bff5
      The rationale behind this being that it is close too close to the first access of the data pointed by the pointer and is of no significant improvement as seen in the benchmarks.
      
      PiperOrigin-RevId: 670574898
      Change-Id: I43a495f23871a2870f4ffd9ab9232083d9668c79
      Abseil Team committed
  20. 30 Aug, 2024 1 commit
  21. 29 Aug, 2024 1 commit
    • Allow slow and fast abseil hardening checks to be enabled independently. · 1031858e
      This change adds a new macro, ABSL_HARDENING_ASSERT_SLOW, which can be used for hardening assertions which have too great a performance impact to enable widely.  It also adds an additional supported value for ABSL_OPTION_HARDENED to only enable assertions which are not slow.  ABSL_OPTION_HARDENED=1 will continue to enable all hardening assertions, while ABSL_OPTION_HARDENED=2 will only enable assertions not marked as SLOW.
      
      PiperOrigin-RevId: 668976425
      Change-Id: I12cb209715d5b359c4093cc8c62e16794d7729b3
      Abseil Team committed
  22. 28 Aug, 2024 3 commits
  23. 27 Aug, 2024 1 commit
  24. 26 Aug, 2024 1 commit
  25. 23 Aug, 2024 1 commit