PageRenderTime 162ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/package/ripgrep/0001-puts-jemalloc-allocator-behind-a-cargo-feature-flag.patch

https://gitlab.com/atilla/buildroot
Patch | 131 lines | 116 code | 15 blank | 0 comment | 0 complexity | e0255629d2adc2a37d65f7f7840e2818 MD5 | raw file
  1. From 68c2a4d7a5d9b46f65121958fdb12d5270bfd1b6 Mon Sep 17 00:00:00 2001
  2. From: Jonathan Stites <mail@jonstites.com>
  3. Date: Wed, 6 May 2020 12:55:35 +0000
  4. Subject: [PATCH] puts jemalloc allocator behind a cargo feature flag
  5. Retrieved from: https://github.com/BurntSushi/ripgrep/pull/1569
  6. Moves jemalloc behind a feature for musl builds, where it is not
  7. supported by the upstream project, so ripgrep will fail to build.
  8. Signed-off-by: Sam Voss <sam.voss@gmail.com>
  9. ---
  10. .github/workflows/ci.yml | 6 ++++++
  11. .github/workflows/release.yml | 8 +++++++-
  12. Cargo.toml | 8 +++++++-
  13. README.md | 9 +++++++++
  14. crates/core/main.rs | 8 ++++++--
  15. 5 files changed, 35 insertions(+), 4 deletions(-)
  16. diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
  17. index ab154ec..aa567d9 100644
  18. --- a/.github/workflows/ci.yml
  19. +++ b/.github/workflows/ci.yml
  20. @@ -149,6 +149,12 @@ jobs:
  21. if: matrix.target != ''
  22. run: ${{ env.CARGO }} test --verbose --workspace ${{ env.TARGET_FLAGS }}
  23. + - name: Run tests with jemalloc (Musl)
  24. + # We only use the jemalloc allocator when building with musl.
  25. + # The system allocator is good enough for other platforms.
  26. + if: matrix.os == 'nightly-musl'
  27. + run: ${{ env.CARGO }} test --verbose --all --features jemalloc ${{ env.TARGET_FLAGS }}
  28. +
  29. - name: Test for existence of build artifacts (Windows)
  30. if: matrix.os == 'windows-2019'
  31. shell: bash
  32. diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
  33. index 7cfb6a4..ad6b82d 100644
  34. --- a/.github/workflows/release.yml
  35. +++ b/.github/workflows/release.yml
  36. @@ -133,7 +133,13 @@ jobs:
  37. echo "target flag is: ${{ env.TARGET_FLAGS }}"
  38. echo "target dir is: ${{ env.TARGET_DIR }}"
  39. - - name: Build release binary
  40. + - name: Build release binary (linux)
  41. + if: matrix.build == 'linux'
  42. + # Use jemalloc allocator for much better performance over the musl default allocator
  43. + run: ${{ env.CARGO }} build --verbose --release --features "pcre2 jemalloc" ${{ env.TARGET_FLAGS }}
  44. +
  45. + - name: Build release binary (non-linux)
  46. + if: matrix.build != 'linux'
  47. run: ${{ env.CARGO }} build --verbose --release --features pcre2 ${{ env.TARGET_FLAGS }}
  48. - name: Strip release binary (linux and macos)
  49. diff --git a/Cargo.toml b/Cargo.toml
  50. index fb78fcb..0d34b1e 100644
  51. --- a/Cargo.toml
  52. +++ b/Cargo.toml
  53. @@ -56,8 +56,9 @@ version = "2.33.0"
  54. default-features = false
  55. features = ["suggestions"]
  56. -[target.'cfg(all(target_env = "musl", target_pointer_width = "64"))'.dependencies.jemallocator]
  57. +[dependencies.jemallocator]
  58. version = "0.3.0"
  59. +optional = true
  60. [build-dependencies]
  61. lazy_static = "1.1.0"
  62. @@ -75,6 +76,11 @@ walkdir = "2"
  63. [features]
  64. simd-accel = ["grep/simd-accel"]
  65. pcre2 = ["grep/pcre2"]
  66. +# The jemalloc allocator is used for improved
  67. +# performance on x86 musl builds.
  68. +# Cargo does not yet support platform-specific features
  69. +# https://github.com/rust-lang/cargo/issues/1197
  70. +jemalloc = ["jemallocator"]
  71. [profile.release]
  72. debug = 1
  73. diff --git a/README.md b/README.md
  74. index 46938bc..9917b29 100644
  75. --- a/README.md
  76. +++ b/README.md
  77. @@ -406,6 +406,15 @@ build a static executable with MUSL and with PCRE2, then you will need to have
  78. `musl-gcc` installed, which might be in a separate package from the actual
  79. MUSL library, depending on your Linux distribution.
  80. +When building with the MUSL target on Linux, it is recommended to use the
  81. +jemalloc allocator for performance:
  82. +
  83. +```
  84. +$ rustup target add x86_64-unknown-linux-musl
  85. +$ cargo build --release --target x86_64-unknown-linux-musl --features jemalloc
  86. +```
  87. +
  88. +
  89. ### Running tests
  90. diff --git a/crates/core/main.rs b/crates/core/main.rs
  91. index 47385de..c9dae5a 100644
  92. --- a/crates/core/main.rs
  93. +++ b/crates/core/main.rs
  94. @@ -31,7 +31,7 @@ mod subject;
  95. // have the fastest version of everything. Its goal is to be small and amenable
  96. // to static compilation.) Even though ripgrep isn't particularly allocation
  97. // heavy, musl's allocator appears to slow down ripgrep quite a bit. Therefore,
  98. -// when building with musl, we use jemalloc.
  99. +// we expose a feature for using jemalloc when building with musl.
  100. //
  101. // We don't unconditionally use jemalloc because it can be nice to use the
  102. // system's default allocator by default. Moreover, jemalloc seems to increase
  103. @@ -39,7 +39,11 @@ mod subject;
  104. //
  105. // Moreover, we only do this on 64-bit systems since jemalloc doesn't support
  106. // i686.
  107. -#[cfg(all(target_env = "musl", target_pointer_width = "64"))]
  108. +#[cfg(all(
  109. + target_env = "musl",
  110. + target_pointer_width = "64",
  111. + feature = "jemalloc"
  112. +))]
  113. #[global_allocator]
  114. static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;
  115. --
  116. 2.32.0