Skip to content

runtime: improve timer performance #53953

@OmidHekayati

Description

@OmidHekayati

Needed changes to improve performance (At least in theory):

  • Change timers []*timer to timers []timerBucket
  • Make new timerBucket struct as
type timerBucket struct {
	timer *timer
	// Two reason to have timer when here:
	// - hot cache to prevent dereference timer to get when field
	// - It can be difference with timer when filed in timerModifiedXX status.
	when int64
}
  • Delete when int64 from timer struct in favor of timerBucket when field.
  • Rename nextwhen int64 to when int64 in timer struct
  • Make some few other changes to respect above changes in related functions

By this changes, we claim that we improve performance in siftupTimer and siftdownTimer when need to compare timers added when to timing heap, we don't need to get data from many different location in the memory (dereference many timers) and we have timers added when in sequential array.

Additional suggestions to improve code readability:

  • make timer.go and timers.go in runtime package
  • make timers struct
  • move timers field from p struct in runtime2.go to timers struct and embed this struct instead
  • move all timers logic from many files in runtime package to timers.go such as logics in time.go - almost everthing, proc.go - checkTimers, ...

p.s: If the idea is ok, I can help to make changes by send a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.compiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    Status

    Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions