Skip to content

Releases: swift-foundations/swift-resource-pool

0.2.0

Choose a tag to compare

@github-actions github-actions released this 21 Dec 21:25
feat: make package Foundation-free for Swift Embedded compatibility

- Replace UUID with UInt64 counter for waiter identification
- Update linting config to resolve swift-format/swiftlint conflicts
- Configure swift-format to disable trailing commas (Swift 5.9+ compat)

0.1.4

Choose a tag to compare

@coenttb coenttb released this 19 Dec 17:57

What's Changed

  • Lowered: Platform requirements to macOS 13+, iOS 16+, tvOS 16+, watchOS 9+ (#7) - thanks @loparker-CLGX!
  • Added: iOS simulator tests to CI
  • Changed: Restructured Package@swift files (Package.swift now Swift 6.0, Package@swift-5.9.swift for older toolchains)
  • Fixed: Skip timing-sensitive tests on iOS simulator

Full Changelog: 0.1.3...0.1.4

0.1.3

Choose a tag to compare

@github-actions github-actions released this 19 Dec 17:14
feat: lower platform requirements and add iOS CI

- Lower all platforms to minimum viable: macOS 13, iOS 16, tvOS 16, watchOS 9
- Restructure Package files: Package.swift now Swift 6.0 (highest)
- Rename Package@swift-6.0.swift to Package@swift-5.9.swift for older toolchains
- Add iOS simulator tests to CI workflow

Co-authored-by: loparker-CLGX <loparker@corelogic.com>

0.1.2

Choose a tag to compare

@github-actions github-actions released this 30 Oct 18:46
Release 0.1.2

- Fixed release build compatibility by making waitForWarmupCompletion available in all build configurations

- Standardized README with 2-badge format and comprehensive structure
- Added 13 verification tests ensuring all README code examples compile and execute
- Added Table of Contents for improved navigation
- Added Related Packages section

- Added comprehensive CI workflow with dual Swift version testing (6.0, 6.2)
- Added multi-platform support (macOS, Linux, Windows)
- Added Point-Free style automation (swift-format, swiftlint, dependabot)
- Optimized for reliability: macOS runs release builds only to avoid Swift Testing framework crashes
- Improved test stability: adjusted performance benchmark thresholds for CI environment variability

- All 58 tests passing across all platforms
- Enhanced test coverage with README verification suite
- Performance benchmarks tuned for CI environment stability

swift-resource-pool v0.1.0 πŸš€

Choose a tag to compare

@coenttb coenttb released this 07 Oct 13:19

swift-resource-pool v0.1.0 πŸš€

Production-ready actor-based resource pool for Swift

A high-performance, thread-safe resource pooling solution that eliminates the thundering herd problem through direct resource handoff, ensures fairness with FIFO ordering, and provides comprehensive metrics for production monitoring.


✨ Key Features

🎯 Zero Thundering Herd

  • Direct handoff: Resources go to exactly ONE waiting task (no broadcast storms)
  • O(1) wakeup: Efficient queue management with 90-95% handoff rate
  • Proven scalability: Handles 200+ concurrent waiters without degradation

βš–οΈ Fairness & Predictability

  • FIFO queue: Prevents starvation, ensures fair ordering
  • LIFO resource selection: Optimizes cache locality
  • Consistent performance: P99/Avg latency ratio of only 1.2x

πŸ›‘οΈ Production Ready

  • Cancellation-safe: Guaranteed cleanup on task cancellation
  • Actor-isolated: Thread-safe without locks
  • Zero leaks: All resources and continuations properly managed
  • Defensive programming: Parameter validation, overflow protection

⚑ High Performance

  • Up to 2,395 ops/sec throughput (capacity-dependent)
  • Near-linear scaling: 3.28x improvement for 3.3x load increase
  • Efficient warmup: Non-blocking background pre-creation
  • Automatic cleanup: Validation and reset between uses

πŸ“Š Comprehensive Observability

  • Real-time statistics (utilization, queue depth, backpressure)
  • Production metrics (acquisitions, timeouts, handoffs, wait times)
  • 45 tests with 100% pass rate

πŸ“¦ Installation

Add to your Package.swift:

dependencies: [
    .package(url: "https://github.com/coenttb/swift-resource-pool", from: "0.1.0")
]

πŸš€ Quick Start

import ResourcePool

// Define your poolable resource
actor DatabaseConnection: PoolableResource {
    struct Config: Sendable {
        let host: String
        let port: Int
    }
    
    static func create(config: Config) async throws -> DatabaseConnection {
        // Create connection
    }
    
    func validate() async -> Bool {
        // Check if connection is alive
    }
    
    func reset() async throws {
        // Reset connection state
    }
}

// Create pool with 10 connections
let pool = try await ResourcePool<DatabaseConnection>(
    capacity: 10,
    resourceConfig: .init(host: "localhost", port: 5432),
    warmup: true
)

// Use resources safely with automatic cleanup
let results = try await pool.withResource { connection in
    try await connection.query("SELECT * FROM users")
}

πŸ“ˆ Performance (Verified)

Metric Value
Throughput (cap 20, 100 tasks) 2,395 ops/sec
Scalability (30β†’100 waiters) 3.28x improvement
Handoff efficiency 90-95%
P99 latency (under contention) 171ms
P99/Avg ratio 1.2x
Stress test (500 concurrent ops) 0 timeouts

βœ… Test Coverage

  • 45 tests across 4 test suites
  • 100% pass rate in production
  • Basic functionality (7 tests)
  • Concurrency & fairness (13 tests)
  • Lifecycle & cleanup (12 tests)
  • Performance benchmarks (13 tests)

πŸ”§ Requirements

  • Swift 5.9+ (Swift 6.0 language mode for strict concurrency)
  • macOS 14+, iOS 17+, tvOS 17+, watchOS 10+, Linux
  • Zero external dependencies

πŸ“š Documentation

See the README for:

  • Detailed usage examples (Database, HTTP Client, WKWebView)
  • API reference
  • Advanced patterns (global actors, monitoring, graceful shutdown)
  • Real-world performance benchmarks

πŸ™ Acknowledgments

Built with Swift's modern concurrency features: actors, async/await, and structured concurrency.


πŸ“„ License

Apache 2.0 with Runtime Library Exception


Ready for production use! πŸŽ‰

Report issues: https://github.com/coenttb/swift-resource-pool/issues
Discussions: https://github.com/coenttb/swift-resource-pool/discussions