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

runtime: timer.seq field seems unnecessary #46457

Closed
someblue opened this issue May 30, 2021 · 2 comments
Closed

runtime: timer.seq field seems unnecessary #46457

someblue opened this issue May 30, 2021 · 2 comments

Comments

@someblue
Copy link

@someblue someblue commented May 30, 2021

What's the purpose of seq field in runtimeTimer?

According to runtime/time.go implementation, runtime/time.go define timer struct, including seq field. This seq field will not be modified by runtime and always keep the value when timer struct was created. The only place to use seq field is the callback of timer.f in runOneTimer.

However, in time/sleep.go, this seq field isn't set when initializing

And the callback runtimeTImer.f doesn't use this field too:

At first I guess this is for some compatible reason. But even when go1.0.1 this seq field is not used: https://github.com/golang/go/blob/go1.0.1/src/pkg/time/sleep.go

The comment each time calling f(arg, now) in the timer goroutine in https://github.com/golang/go/blob/go1.16.4/src/runtime/time.go#L24 is inconsistent with the behavior.

It seems to me the seq field should be removed to help understand source code of timer more easily without confusion, and maybe improve the performance (very very slightly).

Should this seq field be remove? Please let me known if I miss something other!

@seankhliao seankhliao changed the title timer: runtimeTimer seq field seem unnecessary runtime: timer.seq field seems unnecessary May 30, 2021
@ZekeLu
Copy link

@ZekeLu ZekeLu commented May 31, 2021

dvyukov 2014/08/30 12:27:38

On 2014/08/29 18:53:11, rsc wrote: > This seems unrelated. Remove.

This is required for Go netpoll. Previously I stored PollDesc* into arg.data, and seq into arg.type. Now *pollDesc occupies whole arg.

see https://codereview.appspot.com/132910043/diff/260001/src/pkg/runtime/time.go#newcode25

Loading

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented May 31, 2021

We don't use the issue tracker for discussions, only for actionable bug reports. For questions and discussions, see https://golang.org/wiki/Questions.

As the above referenced comment points out, the seq field is used in runtime/netpoll.go, when runOneTimer passes it back.

Loading

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

Successfully merging a pull request may close this issue.

None yet
4 participants