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

Add time.monotonic #787

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Add time.monotonic #787

wants to merge 1 commit into from

Conversation

mentalisttraceur
Copy link

@mentalisttraceur mentalisttraceur commented Jul 23, 2021

Added time.monotonic as suggested in #699 - it is a trivial one-line implementation based on performance.now.

The docstring is a simplified version of the official Python documentation.

@mentalisttraceur
Copy link
Author

mentalisttraceur commented Jul 23, 2021

This comment is non-essential to review+merge this PR.

P.S. My apologies for remaking #765 - I wanted to be proactively helpful and update this to fix the spurious merge conflict that got introduced by other upstream changes. But since I had deleted the fork from my account (I don't like having forks sitting around on my GitHub), recreating the pull request seemed to be the only way for me to do so.

But to be clear, I still really don't want forks sitting around on my GitHub account, and after not getting any response on that copy of this trivial PR for seven months, I'm not feeling very optimistic or patient about it being worth it to do so, so we're now in the same state: the fork is already gone from my account and thus I can't update this PR.

The difference this time is that I won't be recreating a third time, unless I get some explicit signal that the help is actually wanted.

@mentalisttraceur
Copy link
Author

mentalisttraceur commented Jul 28, 2021

This comment is non-essential to review+merge this PR.

Every once in a while I think "maybe it is worth it to have one or more tests for this", but what, exactly, would such tests be proving?

We don't want to be testing the behavior of performance.now() itself, because if there's a bug in that, that's not Transcrypt's problem - whoever implemented performance.now needs to be testing that.

I presume we don't want Transcrypt to be in the business of implementing

  • backwards-compatible polyfils for performance.now which try to degrade while at least maintaining monotonicity on browsers that don't have it, or

  • workarounds for buggy implementations of performance.now if there is any browser that requires that.

I also don't know of any differences in browser APIs, now or on the horizon, which would force a more complex implementation of time.monotonic on Transcrypt. So I don't see a reason for the implementation to ever change on purpose.

I also don't think Transcrypt wants to be in the business of supporting old browsers which don't have performance.now at all. But even if we do, the implementation in this PR doesn't prevent importing the time module on such browsers - it's just that if code on such a browser calls time.monotonic(), it will get the same exception as it would if it tried calling performance.now(). This seems reasonable.

So what exactly is the testable surface area? That we didn't make a typo? That someone didn't accidentally delete or add a line or a character? That sounds silly, but I do see the value of that - it's a good safety railing to have against accidents. So we could do a one-liner test
verifying that time.monotonic returns a number, and if that number seems to be approximately the output of performance.now() / 1000:

int(time.monotonic()) <= int(performance.now() / 1000)

I didn't initially put that in because it seems like it's almost redundant, and it takes more work to verify that the test is appropriately scoped and correct than to just verify the code itself.

But I will gladly go ahead and add that if I get an explicit statement that this is wanted. And I'm open to other suggestions about what's worth testing, because maybe I'm missing something in my above reasoning.

That's why my initial description of #765 that I wrote back in December 2020 said

Please advise if you want any tests for it!

@mentalisttraceur
Copy link
Author

mentalisttraceur commented May 26, 2022

This comment is non-essential to review+merge this PR.

and it takes more work to verify that the test is appropriately scoped and correct than to just verify the code itself

Case in point:

I don't remember if <= is guaranteed in JavaScript to evaluate the left operand before the right operand.

Knowing me, I probably checked that when I first wrote that example test line. But right now I don't remember. And if it's not guaranteed, then that test is just wrong/unreliable/nondeterministic.

In the amount of time it even took me to remember this possibility, I can validate that this time.performance is still implemented correctly. In the amount of time it would take me to describe it, or in the amount of time it would take me to look up relevant ordering guarantees in JavaScript, I could do that several times over.

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.

None yet

1 participant