Skip to content

Commit 7e74a90

Browse files
authored
perf: update ferroid for better performance during encode/decode (#879)
This PR updates ferroid to the latest release which increases performance of encode/decode by another 10-15%. It also introduces a more ergonomic `ULID::now()` method.
1 parent 3644df1 commit 7e74a90

File tree

5 files changed

+7
-8
lines changed

5 files changed

+7
-8
lines changed

testcontainers/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ tokio = { version = "1", features = ["macros", "fs", "rt-multi-thread", "process
4646
tokio-stream = "0.1.15"
4747
astral-tokio-tar = "0.5.6"
4848
tokio-util = { version = "0.7.10", features = ["io"] }
49-
ferroid = { version = "0.8.2", features = ["std", "ulid", "base32"] }
49+
ferroid = { version = "0.8.7", features = ["std", "ulid", "base32"] }
5050
url = { version = "2", features = ["serde"] }
5151
uuid = { version = "1.8.0", features = ["v4"], optional = true }
5252

testcontainers/src/core/client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ impl Client {
490490
.await
491491
.map_err(ClientError::CopyToContainerError)?;
492492

493-
let session = ULID::from_datetime(std::time::SystemTime::now()).encode();
493+
let session = ULID::now().encode();
494494

495495
let mut builder = BuildImageOptionsBuilder::new()
496496
.dockerfile("Dockerfile")

testcontainers/src/core/containers/host.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ fn prepare_host_exposure<I: Image>(
166166
}
167167
}
168168

169-
let suffix = ULID::from_datetime(std::time::SystemTime::now()).encode();
169+
let suffix = ULID::now().encode();
170170
let password = format!("tc-{}", suffix.as_str());
171171

172172
Ok(Some(HostExposurePlan {

testcontainers/src/runners/async_runner.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ use crate::{
2424

2525
const DEFAULT_STARTUP_TIMEOUT: Duration = Duration::from_secs(60);
2626
#[cfg(feature = "reusable-containers")]
27-
static TESTCONTAINERS_SESSION_ID: std::sync::OnceLock<ferroid::id::ULID> =
28-
std::sync::OnceLock::new();
27+
static TESTCONTAINERS_SESSION_ID: std::sync::LazyLock<ferroid::id::ULID> =
28+
std::sync::LazyLock::new(ferroid::id::ULID::now);
2929

3030
#[doc(hidden)]
3131
/// A unique identifier for the currently "active" `testcontainers` "session".
@@ -41,8 +41,7 @@ static TESTCONTAINERS_SESSION_ID: std::sync::OnceLock<ferroid::id::ULID> =
4141
/// as the container name, labels, and network would all still match.
4242
#[cfg(feature = "reusable-containers")]
4343
pub(crate) fn session_id() -> &'static ferroid::id::ULID {
44-
TESTCONTAINERS_SESSION_ID
45-
.get_or_init(|| ferroid::id::ULID::from_datetime(std::time::SystemTime::now()))
44+
&TESTCONTAINERS_SESSION_ID
4645
}
4746

4847
#[async_trait]

testcontainers/tests/host_port_exposure.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ async fn host_port_exposure_is_scoped_per_container() -> Result<()> {
194194
let second_host_port = start_test_http_server("second-host-service")?;
195195

196196
// Generate unique identifiers for network and containers to avoid conflicts
197-
let suffix = ULID::from_datetime(std::time::SystemTime::now()).encode();
197+
let suffix = ULID::now().encode();
198198
let network_name = format!("tc-host-port-net-{}", suffix.as_str());
199199
let first_container_name = format!("host-port-first-{}", suffix.as_str());
200200
let second_container_name = format!("host-port-second-{}", suffix.as_str());

0 commit comments

Comments
 (0)