1. 13 Nov, 2024 1 commit
    • Reduce memory consumption of structured logging proto encoding by passing tag value · 3a3b7e46
      The proto encoding for structured logging currently pessimistically assumes each numeric tag value for encoded fields could be up to `UINT64_MAX`.
      
      In practice, the tag values we care about are all < 16, which only requires 1 byte
      of buffer space.
      
      This CL improves the memory consumption by specifying the tag value when
      calculating the buffer size needed for the structured logging proto.
      
      PiperOrigin-RevId: 696118135
      Change-Id: Iee67deef568cb4df7646d3ddd40c14b490ca0e45
      Abseil Team committed
  2. 11 Nov, 2024 2 commits
  3. 08 Nov, 2024 4 commits
  4. 07 Nov, 2024 1 commit
  5. 06 Nov, 2024 3 commits
  6. 05 Nov, 2024 1 commit
  7. 04 Nov, 2024 2 commits
  8. 01 Nov, 2024 1 commit
  9. 30 Oct, 2024 1 commit
  10. 28 Oct, 2024 1 commit
  11. 23 Oct, 2024 5 commits
  12. 22 Oct, 2024 1 commit
    • Marks absl::Span as view and borrowed_range, like std::span. · 87831365
      This allows containers that either optimize based on these
      concepts or produce lifetime warnings based on them to
      handle absl::Span appropriately. An example is Chromium's
      base::span, which warns more aggressively about construction
      from rvalues that are not borrowed ranges.
      
      This only has an effect for codebases using C++20. While
      many such codebases will presumably also be using std::span
      directly, they may use absl::Span for backwards compat, or
      compile against libraries that do so.
      
      Also fixes lint's that fired when I tried to edit this.
      
      PiperOrigin-RevId: 688552975
      Change-Id: I603e04cd74d60ac6b65754ac73037d7f0ab457fe
      Abseil Team committed
  13. 17 Oct, 2024 1 commit
  14. 15 Oct, 2024 1 commit
  15. 14 Oct, 2024 1 commit
  16. 11 Oct, 2024 1 commit
  17. 10 Oct, 2024 2 commits
  18. 08 Oct, 2024 1 commit
  19. 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
  20. 27 Sep, 2024 1 commit
  21. 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
  22. 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
  23. 23 Sep, 2024 1 commit
  24. 20 Sep, 2024 1 commit
  25. 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
  26. 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