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

viml/profile: revert proftime_T to unsigned type #10521

Merged
merged 1 commit into from Jul 16, 2019

Conversation

justinmk
Copy link
Member

@justinmk justinmk commented Jul 16, 2019

  • reltimestr(): Produce negative value by comparing the unsigned proftime_T value to INT64_MAX.

#10452 (comment)

  1. The interfaces of nearly all platforms return uint64_t. INT64_MAX is only half of that.
  2. Low-level interfaces like this typically define that there is no fixed starting point. The only guarantees are that it's (a) monotonically increasing at a rate that (b) matches real time.

ref 06af88c
fix #10452

cc @aktau

- reltimestr(): Produce negative value by comparing the unsigned
  proftime_T value to INT64_MAX.

neovim#10452 (comment)
1. The interfaces of nearly all platforms return uint64_t. INT64_MAX is
   only half of that.
2. Low-level interfaces like this typically define that there is no
   fixed starting point. The only guarantees are that it's (a)
   monotonically increasing at a rate that (b) matches real time.

ref 06af88c
fix neovim#10452
@justinmk justinmk force-pushed the profile branch 3 times, most recently from a5a112a to 803749a Compare July 16, 2019 15:43
@justinmk justinmk added compatibility compatibility with Vim or older Neovim vimscript labels Jul 16, 2019
@justinmk justinmk merged commit bab24a8 into neovim:master Jul 16, 2019
@justinmk justinmk deleted the profile branch July 16, 2019 18:10
///
/// @return -1, 0, or +1
static inline int sgn64(int64_t x) FUNC_ATTR_CONST
/// @return signed representation of the given time value
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry for the extremely delayed review. I think the CL is good, but I had one more thought.

Being exposed to Go a lot made me think that I would solve it with two distinct types:

  • A type for points in time (proftime_T).
  • A type for the subtraction of two points in time (duration_T or something else). This could be unsigned for negative durations. profile_sub would take two proftime_T's and return a duration_T.

(It's been a while, but I think C's automatic type conversion might make accidentally assigning one to the other far too easy, and it's not worth defining two types.)

At first sight, they're semantically quite different. One is an absolute point in time (though we don't know the starting point), and the other is a duration.

On second look, there's also something to be said for keeping them as the same type. Essentially, proftime_T (as defined above) is the duration since the processor was started. When subtracting two proftime_T's, it's just rebasing the starting point to the second operand.

I guess what I'm trying to say is: the way it is right now is IMHO a decent tradeoff, as C won't provide too much protection either way (Go would complain if one doesn't cast, even for the same underlying type).

The only thing I'd change is to document that profile_signed is meant to be used proftime_Ts that are (perhaps indirectly) the result of profile_sub calls.

The comment itself is not that important, maybe if you ever pass over the code again.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks. I will update the comment.

Essentially, proftime_T (as defined above) is the duration since the processor was started.

That was my conclusion as well, though I didn't inspect every call site in the codebase.

justinmk added a commit to justinmk/neovim that referenced this pull request Jul 19, 2019
For "backwards" duration, reltimefloat() should return negative value
like its counterpart reltimestr().

ref bab24a8
ref 06af88c
ref neovim#10521
fix neovim#10452
justinmk added a commit to justinmk/neovim that referenced this pull request Jul 19, 2019
For "backwards" duration, reltimefloat() should return negative value
like its counterpart reltimestr().

ref bab24a8
ref 06af88c
ref neovim#10521
fix neovim#10452
justinmk added a commit that referenced this pull request Jul 20, 2019
For "backwards" duration, reltimefloat() should return negative value
like its counterpart reltimestr().

ref bab24a8
ref 06af88c
ref #10521
fix #10452
timeyyy pushed a commit to timeyyy/neovim that referenced this pull request Aug 9, 2019
- reltimestr(): Produce negative value by comparing the unsigned
  proftime_T value to INT64_MAX.

neovim#10452 (comment)
1. The interfaces of nearly all platforms return uint64_t. INT64_MAX is
   only half of that.
2. Low-level interfaces like this typically define that there is no
   fixed starting point. The only guarantees are that it's (a)
   monotonically increasing at a rate that (b) matches real time.

ref 06af88c
fix neovim#10452
timeyyy pushed a commit to timeyyy/neovim that referenced this pull request Aug 9, 2019
For "backwards" duration, reltimefloat() should return negative value
like its counterpart reltimestr().

ref bab24a8
ref 06af88c
ref neovim#10521
fix neovim#10452
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compatibility compatibility with Vim or older Neovim vimscript
Projects
None yet
Development

Successfully merging this pull request may close these issues.

reltimestr(reltime(newer_time, older_time)) does not return negative number
2 participants