Repository: launchbadge/sqlx
File: sqlx-core/src/pool/inner.rs (Rust)

Code before:
        )
            .await
            .map_err(|_| Error::PoolTimedOut)??;

        let acquired_after = Instant::now() - acquire_started_at;

        let acquire_time_level = match self.acquire_slow_level {
            Some(level) => {
                if acquired_after >= self.options.acquire_slow_after {
                    private_tracing_dynamic_event!(
                        target: "sqlx::pool",
                        level,
                        aquired_after_secs = acquired_after.as_secs_f64(),
                        slow_acquire_threshold_secs = self.options.acquire_slow_after.as_secs_f64(),
                        "acquired connection, but time to acquire exceeded slow threshold"
                    );

                    // Suppress non-slow acquire logging
                    None
                } else {
                    // Fallback on non-slow logging, if configured
                    self.acquire_time_level
                }
            }
            // Slow logging not configured
            None => self.acquire_time_level,
        };

        if let Some(level) = acquire_time_level {
            private_tracing_dynamic_event!(
                target: "sqlx::pool",
                level,
                aquired_after_secs = acquired_after.as_secs_f64(),
                "acquired connection"
            );
        }

        Ok(acquired)
    }

    pub(super) async fn connect(
        self: &Arc<Self>,
        deadline: Instant,
        guard: DecrementSizeGuard<DB>,
    ) -> Result<Floating<DB, Live<DB>>, Error> {
        if self.is_closed() {
            return Err(Error::PoolClosed);
        }

        let mut backoff = Duration::from_millis(10);
        let max_backoff = deadline_as_timeout::<DB>(deadline)? / 5;

Review comment (performance):
This can be significantly simplified:

```suggestion
        let acquire_slow_level = self.acquire_slow_level.filter(|_| acquired_after >= self.options.acquire_slow_after);

        if let Some(level) = acquire_slow_level {
            private_tracing_dynamic_event!(
                target: "sqlx::pool",
                level,
                aquired_after_secs = acquired_after.as_secs_f64(),
                slow_acquire_threshold_secs = self.options.acquire_slow_after.as_secs_f64(),
                 "acquired connection, but time to acquire exceeded slow threshold"
            );
        } else if let Some(level) = self.acquire_time_level {
            private_tracing_dynamic_event!(
                target: "sqlx::pool",
                level,
                aquired_after_secs = acquired_after.as_secs_f64(),
                "acquired connection"
            );
        }
```

The target should also probably be `sqlx::pool::acquire` to allow for more specific filtering.

Code after:
        )
            .await
            .map_err(|_| Error::PoolTimedOut)??;

        let acquired_after = acquire_started_at.elapsed();

        let acquire_slow_level = self
            .acquire_slow_level
            .filter(|_| acquired_after > self.options.acquire_slow_threshold);

        if let Some(level) = acquire_slow_level {
            private_tracing_dynamic_event!(
                target: "sqlx::pool::acquire",
                level,
                aquired_after_secs = acquired_after.as_secs_f64(),
                slow_acquire_threshold_secs = self.options.acquire_slow_threshold.as_secs_f64(),
                "acquired connection, but time to acquire exceeded slow threshold"
            );
        } else if let Some(level) = self.acquire_time_level {
            private_tracing_dynamic_event!(
                target: "sqlx::pool::acquire",
                level,
                aquired_after_secs = acquired_after.as_secs_f64(),
                "acquired connection"
            );
        }

        Ok(acquired)
    }

    pub(super) async fn connect(
        self: &Arc<Self>,
        deadline: Instant,
        guard: DecrementSizeGuard<DB>,
    ) -> Result<Floating<DB, Live<DB>>, Error> {
        if self.is_closed() {
            return Err(Error::PoolClosed);
        }

        let mut backoff = Duration::from_millis(10);
        let max_backoff = deadline_as_timeout::<DB>(deadline)? / 5;

        loop {
            let timeout = deadline_as_timeout::<DB>(deadline)?;

            // clone the connect options arc so it can be used without holding the RwLockReadGuard
            // across an async await point
            let connect_options = self
                .connect_options
                .read()
                .expect("write-lock holder panicked")