-
Notifications
You must be signed in to change notification settings - Fork 34
feat(minor): Disable jemalloc using package traits #347
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
JaapWijnen
wants to merge
6
commits into
ordo-one:main
Choose a base branch
from
JaapWijnen:disable-jemalloc-using-package-traits
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+191
−57
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
60c798e
add specific package file for 5.9
JaapWijnen 4a56df4
update Package.swift tools to 6.1
JaapWijnen 809afaa
update Package.swift to enable jemalloc using traits
JaapWijnen c04a0e1
fix: add @preconcurrency to imports in BenchmarkCommandPlugin.swift
JaapWijnen f267450
rename trait from EnableJemalloc to Jemalloc
JaapWijnen 2566488
enable Jemalloc trait by default
JaapWijnen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,160 @@ | ||
| // swift-tools-version: 5.9 | ||
|
|
||
| import PackageDescription | ||
|
|
||
| import class Foundation.ProcessInfo | ||
|
|
||
| // If the environment variable BENCHMARK_DISABLE_JEMALLOC is set, we'll build the package without Jemalloc support | ||
| let disableJemalloc = ProcessInfo.processInfo.environment["BENCHMARK_DISABLE_JEMALLOC"] | ||
|
|
||
| let package = Package( | ||
| name: "Benchmark", | ||
| platforms: [ | ||
| .macOS(.v13), | ||
| .iOS(.v16), | ||
| ], | ||
| products: [ | ||
| .plugin(name: "BenchmarkCommandPlugin", targets: ["BenchmarkCommandPlugin"]), | ||
| .plugin(name: "BenchmarkPlugin", targets: ["BenchmarkPlugin"]), | ||
| .library( | ||
| name: "Benchmark", | ||
| targets: ["Benchmark"] | ||
| ), | ||
| ], | ||
| dependencies: [ | ||
| .package(url: "https://github.com/apple/swift-system.git", .upToNextMajor(from: "1.1.0")), | ||
| .package(url: "https://github.com/apple/swift-argument-parser.git", .upToNextMajor(from: "1.1.0")), | ||
| .package(url: "https://github.com/ordo-one/TextTable.git", .upToNextMajor(from: "0.0.1")), | ||
| .package(url: "https://github.com/HdrHistogram/hdrhistogram-swift.git", .upToNextMajor(from: "0.1.0")), | ||
| .package(url: "https://github.com/apple/swift-atomics.git", .upToNextMajor(from: "1.0.0")), | ||
| ], | ||
| targets: [ | ||
| // Plugins used by users of the package | ||
|
|
||
| // The actual 'benchmark' command plugin | ||
| .plugin( | ||
| name: "BenchmarkCommandPlugin", | ||
| capability: .command( | ||
| intent: .custom( | ||
| verb: "benchmark", | ||
| description: "Run the Benchmark performance test suite." | ||
| ) | ||
| ), | ||
| dependencies: [ | ||
| "BenchmarkTool" | ||
| ], | ||
| path: "Plugins/BenchmarkCommandPlugin" | ||
| ), | ||
|
|
||
| // Plugin that generates the boilerplate needed to interface with the Benchmark infrastructure | ||
| .plugin( | ||
| name: "BenchmarkPlugin", | ||
| capability: .buildTool(), | ||
| dependencies: [ | ||
| "BenchmarkBoilerplateGenerator" | ||
| ], | ||
| path: "Plugins/BenchmarkPlugin" | ||
| ), | ||
|
|
||
| // Tool that the plugin executes to perform the actual work, the real benchmark driver | ||
| .executableTarget( | ||
| name: "BenchmarkTool", | ||
| dependencies: [ | ||
| .product(name: "ArgumentParser", package: "swift-argument-parser"), | ||
| .product(name: "SystemPackage", package: "swift-system"), | ||
| .product(name: "TextTable", package: "TextTable"), | ||
| "Benchmark", | ||
| "BenchmarkShared", | ||
| ], | ||
| path: "Plugins/BenchmarkTool" | ||
| ), | ||
|
|
||
| // Tool that generates the boilerplate | ||
| .executableTarget( | ||
| name: "BenchmarkBoilerplateGenerator", | ||
| dependencies: [ | ||
| .product(name: "ArgumentParser", package: "swift-argument-parser"), | ||
| .product(name: "SystemPackage", package: "swift-system"), | ||
| ], | ||
| path: "Plugins/BenchmarkBoilerplateGenerator" | ||
| ), | ||
|
|
||
| // Tool that simply generates the man page for the BenchmarkPlugin as we can't use SAP in it... :-/ | ||
| .executableTarget( | ||
| name: "BenchmarkHelpGenerator", | ||
| dependencies: [ | ||
| .product(name: "ArgumentParser", package: "swift-argument-parser"), | ||
| "BenchmarkShared", | ||
| ], | ||
| path: "Plugins/BenchmarkHelpGenerator" | ||
| ), | ||
|
|
||
| // Getting OS specific information | ||
| .target( | ||
| name: "CDarwinOperatingSystemStats", | ||
| dependencies: [], | ||
| path: "Platform/CDarwinOperatingSystemStats" | ||
| ), | ||
|
|
||
| // Getting OS specific information | ||
| .target( | ||
| name: "CLinuxOperatingSystemStats", | ||
| dependencies: [], | ||
| path: "Platform/CLinuxOperatingSystemStats" | ||
| ), | ||
|
|
||
| // Hooks for ARC | ||
| .target(name: "SwiftRuntimeHooks"), | ||
|
|
||
| // Shared definitions | ||
| .target(name: "BenchmarkShared"), | ||
|
|
||
| .testTarget( | ||
| name: "BenchmarkTests", | ||
| dependencies: ["Benchmark"] | ||
| ), | ||
| ] | ||
| ) | ||
| // Check if this is a SPI build, then we need to disable jemalloc for macOS | ||
|
|
||
| let macOSSPIBuild: Bool // Disables jemalloc for macOS SPI builds as the infrastructure doesn't have jemalloc there | ||
|
|
||
| #if canImport(Darwin) | ||
| if let spiBuildEnvironment = ProcessInfo.processInfo.environment["SPI_BUILD"], spiBuildEnvironment == "1" { | ||
| macOSSPIBuild = true | ||
| print("Building for SPI@macOS, disabling Jemalloc") | ||
| } else { | ||
| macOSSPIBuild = false | ||
| } | ||
| #else | ||
| macOSSPIBuild = false | ||
| #endif | ||
|
|
||
| // Add Benchmark target dynamically | ||
|
|
||
| // Shared dependencies | ||
| var dependencies: [PackageDescription.Target.Dependency] = [ | ||
| .product(name: "Histogram", package: "hdrhistogram-swift"), | ||
| .product(name: "ArgumentParser", package: "swift-argument-parser"), | ||
| .product(name: "SystemPackage", package: "swift-system"), | ||
| .byNameItem(name: "CDarwinOperatingSystemStats", condition: .when(platforms: [.macOS, .iOS])), | ||
| .byNameItem(name: "CLinuxOperatingSystemStats", condition: .when(platforms: [.linux])), | ||
| .product(name: "Atomics", package: "swift-atomics"), | ||
| "SwiftRuntimeHooks", | ||
| "BenchmarkShared", | ||
| ] | ||
|
|
||
| if macOSSPIBuild == false { // jemalloc always disable for macOSSPIBuild | ||
| if let disableJemalloc, disableJemalloc != "false", disableJemalloc != "0" { | ||
| print("Jemalloc disabled through environment variable.") | ||
| } else { | ||
| package.dependencies += [ | ||
| .package(url: "https://github.com/ordo-one/package-jemalloc.git", .upToNextMajor(from: "1.0.0")) | ||
| ] | ||
| dependencies += [ | ||
| .product(name: "jemalloc", package: "package-jemalloc", condition: .when(platforms: [.macOS, .linux])) | ||
| ] | ||
| } | ||
| } | ||
|
|
||
| package.targets += [.target(name: "Benchmark", dependencies: dependencies)] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Critical Bug: Missing compilation condition definition for
EnableJemalloctraitThe code uses
#if EnableJemallocin source files (MallocStatsProducer+jemalloc.swift and OperatingSystemAndMallocTests.swift), but the Benchmark target doesn't defineEnableJemallocas a compilation condition. Package traits only control dependency resolution - they don't automatically become preprocessor flags.This causes:
#if EnableJemallocblocks are always skipped)Fix: Add the compilation condition to swiftSettings:
The same fix should be applied to BenchmarkTests target (lines 112-131) which also likely needs this compilation condition for its test code.
Spotted by Graphite Agent

Is this helpful? React 👍 or 👎 to let us know.