[libcxx-commits] [libcxx] [libc++] Avoid using ranges::upper_bound in <format> (PR #186781)
via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Apr 23 02:27:40 PDT 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libcxx
Author: Nikolas Klauser (philnik777)
<details>
<summary>Changes</summary>
The `ranges` algorithms take a significant time to instantiate. Replacing `ranges::upper_bound` with `std::upper_bound` reduces the time to parse `<format>` by ~50ms, or 10%.
---
Full diff: https://github.com/llvm/llvm-project/pull/186781.diff
2 Files Affected:
- (modified) libcxx/include/__format/escaped_output_table.h (+3-2)
- (modified) libcxx/utils/generate_escaped_output_table.py (+3-2)
``````````diff
diff --git a/libcxx/include/__format/escaped_output_table.h b/libcxx/include/__format/escaped_output_table.h
index 1401b4637d839..a62c715811a0c 100644
--- a/libcxx/include/__format/escaped_output_table.h
+++ b/libcxx/include/__format/escaped_output_table.h
@@ -61,9 +61,10 @@
#ifndef _LIBCPP___FORMAT_ESCAPED_OUTPUT_TABLE_H
#define _LIBCPP___FORMAT_ESCAPED_OUTPUT_TABLE_H
-#include <__algorithm/ranges_upper_bound.h>
+#include <__algorithm/upper_bound.h>
#include <__config>
#include <__cstddef/ptrdiff_t.h>
+#include <__iterator/access.h>
#include <cstdint>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -868,7 +869,7 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr uint32_t __entries[735] = {
if (__code_point >= 0x000323b0)
return true;
- ptrdiff_t __i = std::ranges::upper_bound(__entries, (__code_point << 14) | 0x3fffu) - __entries;
+ ptrdiff_t __i = std::upper_bound(std::begin(__entries), std::end(__entries), (__code_point << 14) | 0x3fffu) - __entries;
if (__i == 0)
return false;
diff --git a/libcxx/utils/generate_escaped_output_table.py b/libcxx/utils/generate_escaped_output_table.py
index 6be7d128ed5f1..30583dd8cdc85 100755
--- a/libcxx/utils/generate_escaped_output_table.py
+++ b/libcxx/utils/generate_escaped_output_table.py
@@ -142,7 +142,7 @@ def compactPropertyRanges(input: list[PropertyRange]) -> list[PropertyRange]:
if (__code_point >= 0x{unallocated:08x})
return true;
- ptrdiff_t __i = std::ranges::upper_bound(__entries, (__code_point << 14) | 0x3fffu) - __entries;
+ ptrdiff_t __i = std::upper_bound(std::begin(__entries), std::end(__entries), (__code_point << 14) | 0x3fffu) - __entries;
if (__i == 0)
return false;
@@ -216,9 +216,10 @@ def compactPropertyRanges(input: list[PropertyRange]) -> list[PropertyRange]:
#ifndef _LIBCPP___FORMAT_ESCAPED_OUTPUT_TABLE_H
#define _LIBCPP___FORMAT_ESCAPED_OUTPUT_TABLE_H
-#include <__algorithm/ranges_upper_bound.h>
+#include <__algorithm/upper_bound.h>
#include <__config>
#include <__cstddef/ptrdiff_t.h>
+#include <__iterator/access.h>
#include <cstdint>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
``````````
</details>
https://github.com/llvm/llvm-project/pull/186781
More information about the libcxx-commits
mailing list