Skip to content
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

fix: jit-times - Timestamp arithmetic + add warnings for negative times #9484

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

alexyakunin
Copy link

@alexyakunin alexyakunin commented Nov 5, 2024

  1. Plus and minus operators for Timestamp type can produce invalid Timestamps. All of Timestamp parts should be either (0 or positive) or (0 or negative), but statements like result.milliseconds-- don't take this value into account in the next "if".

  2. The reporting there is broken - the tool parses methods.txt in assumption it is produced by a single-threaded app, and it seems that it's not the case in reality. That's why many "self" timings are negative.

  3. I truncate all negative self-times to zero while calculating total.

@alexyakunin
Copy link
Author

@dotnet-policy-service agree

@jonathanpeppers
Copy link
Member

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

public int milliseconds;
public int nanoseconds;

public record struct Timestamp(long nanoseconds) : IComparable {
Copy link
Member

Choose a reason for hiding this comment

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

While moving to store only nanoseconds within the Unix epoch is a massive simplification, it also reduces the amount of time that can be tracked. As this is "nanoseconds of Unix epoch" in a signed 64-bit integer, the maximum time this approach can hold is around 2262-Apr-11. Any date after 23h47min16sec on that date results in a negative value:

(long) (new DateTime(2262, 4, 11, 23, 47, 17) - DateTime.UnixEpoch).TotalNanoseconds
// -9223372036854775808

Given that this is still 238 years away, this probably doesn't matter…

Copy link
Author

@alexyakunin alexyakunin Nov 15, 2024

Choose a reason for hiding this comment

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

No disrespect, but if MS folks think it makes sense write this comment to PR + make others read it... I suspect I understand why there is zero progress with some huge issues like the one this PR is related to.

Space ` ` before `(`.

Use `1_000_000` instead of `1000_000`.

Add `checked()` arithmetic.  We don't want Timestamp.operator+() to wrap around to a negative value; that's not useful.
@jonpryor
Copy link
Member

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants