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

proposal: time: compress implementation for time.Now() #72982

Closed
4 tasks
Guest-615695028 opened this issue Mar 21, 2025 · 0 comments
Closed
4 tasks

proposal: time: compress implementation for time.Now() #72982

Guest-615695028 opened this issue Mar 21, 2025 · 0 comments
Labels
LanguageChange Suggested changes to the Go language LanguageChangeReview Discussed by language change review committee Proposal
Milestone

Comments

@Guest-615695028
Copy link

Guest-615695028 commented Mar 21, 2025

Go Programming Experience

Advanced

Other Languages Experience

C/C++, JavaScript

Related Idea

  • Has this idea, or one like it, been proposed before?
  • Does this affect error handling?
  • Is this about generics?
  • Is this change backward compatible? Breaking the Go 1 compatibility guarantee is a large cost and requires a large benefit

Has this idea, or one like it, been proposed before?

No

Does this affect error handling?

No

Is this about generics?

No

Proposal

Why to differ monotonic time? Simplification will help to reduce running time and make time.Now() more exact.

Compare

func Now() Time {
	sec, nsec, _ := runtimeNow()
	return Time{uint64(nsec), sec + unixToInternal, Local}
}

and

func Now() Time {
	sec, nsec, mono := runtimeNow()
	if mono == 0 {
		return Time{uint64(nsec), sec + unixToInternal, Local}
	}
	mono -= startNano
	sec += unixToInternal - minWall
	if uint64(sec)>>33 != 0 {
		// Seconds field overflowed the 33 bits available when
		// storing a monotonic time. This will be true after
		// March 16, 2157.
		return Time{uint64(nsec), sec + minWall, Local}
	}
	return Time{hasMonotonic | uint64(sec)<<nsecShift | uint64(nsec), mono, Local}
}

Language Spec Changes

None

Informal Change

No response

Is this change backward compatible?

Yes. Nothing else changes to the exported methods of time.Time.

Orthogonality: How does this change interact or overlap with existing features?

No response

Would this change make Go easier or harder to learn, and why?

No response

Cost Description

No response

Changes to Go ToolChain

No response

Performance Costs

No response

Prototype

No response

@Guest-615695028 Guest-615695028 added LanguageChange Suggested changes to the Go language LanguageChangeReview Discussed by language change review committee Proposal labels Mar 21, 2025
@gopherbot gopherbot added this to the Proposal milestone Mar 21, 2025
@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Mar 21, 2025
@golang golang locked as spam and limited conversation to collaborators Mar 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
LanguageChange Suggested changes to the Go language LanguageChangeReview Discussed by language change review committee Proposal
Projects
None yet
Development

No branches or pull requests

3 participants