Skip to content

Add Timer.measure methods #140

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

Merged
merged 1 commit into from
Mar 10, 2025
Merged

Add Timer.measure methods #140

merged 1 commit into from
Mar 10, 2025

Conversation

FranzBusch
Copy link
Member

Motivation

This PR supersedes #135. The goal is to make it easier to measure asynchronous code when using Metrics.

Modification

This PR does:

  • Deprecate the current static method for measuring synchronous code
  • Add a new instance method to measure synchronous code
  • Add a new instance method to measure asynchronous code

@FranzBusch
Copy link
Member Author

@swift-server-bot test this please

@Lukasa
Copy link
Contributor

Lukasa commented Apr 22, 2024

@swift-server-bot add to allowlist

Copy link
Contributor

@gjcairo gjcairo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just a nit about docs.

return try body()
}

/// Convenience for measuring duration of a closure with a provided clock.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: the doc for this method and the non-async version don't match. Maybe remove the last bit to match that one, since we're defaulting the clock param anyways?

Suggested change
/// Convenience for measuring duration of a closure with a provided clock.
/// Convenience for measuring duration of a closure.

@FranzBusch
Copy link
Member Author

@swift-server-bot test this please

@FranzBusch FranzBusch enabled auto-merge (squash) May 9, 2024 09:57
@FranzBusch FranzBusch force-pushed the fb-timer-measure branch 3 times, most recently from 8cc9d38 to 199b458 Compare March 8, 2025 11:46
@FranzBusch FranzBusch added the 🆕 semver/minor Adds new public API. label Mar 8, 2025
@FranzBusch FranzBusch disabled auto-merge March 8, 2025 11:46
@FranzBusch
Copy link
Member Author

@fabianfett @simonjbeaumont @czechboy0 I dusted off this PR again and brought up to the latest Swift standards. If you could take another look that would be great.

@FranzBusch
Copy link
Member Author

@czechboy0 To address your feedback I removed the deprecation. This will allow current adopters or adopter with platform requirements to stay with the existing API.

@czechboy0
Copy link
Contributor

To address your feedback I removed the deprecation. This will allow current adopters or adopter with platform requirements to stay with the existing API.

Thanks, Franz. And the second question - are we okay only offering this new method to packages with the raised OS requirements?

@FranzBusch
Copy link
Member Author

Thanks, Franz. And the second question - are we okay only offering this new method to packages with the raised OS requirements?

Yes, I think that's fine. The other method exists and the intention of the new one is to take advantage of Clock.

# Motivation

This PR supersedes #135. The goal is to make it easier to measure asynchronous code when using `Metrics`.

# Modification

This PR does:
- Deprecate the current static method for measuring synchronous code
- Add a new instance method to measure synchronous code
- Add a new instance method to measure asynchronous code

# Result

It is now easier to measure asynchronous code.
@czechboy0
Copy link
Contributor

Yes, I think that's fine. The other method exists and the intention of the new one is to take advantage of Clock.

Right, it's not a big inconvenience - it might just be confusing that the instance method requires a newer OS (because it uses Clock), but the static method doesn't. We could add a @_disfavoredOverload instance method variant that doesn't use Clock? Up to you.

@FranzBusch
Copy link
Member Author

FranzBusch commented Mar 10, 2025

Right, it's not a big inconvenience - it might just be confusing that the instance method requires a newer OS (because it uses Clock), but the static method doesn't. We could add a @_disfavoredOverload instance method variant that doesn't use Clock? Up to you.

I get your point but I really don't think we should add those. Clock is the way forward and there is the existing static method that provides an escape hatch. We can always add it is somebody asks for it.

@FranzBusch FranzBusch merged commit 3c0f419 into main Mar 10, 2025
22 checks passed
@FranzBusch FranzBusch deleted the fb-timer-measure branch March 10, 2025 09:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🆕 semver/minor Adds new public API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants