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

Stop importing nanotime from runtime via linkname #35

Merged
merged 1 commit into from
Sep 9, 2024

Conversation

maypok86
Copy link
Contributor

@maypok86 maypok86 commented Sep 9, 2024

Hi, the authors of Go decided to lock down the use of linkname. Puddle uses linkname only to import nanotime. This PR implements a simple trick that allows puddle to get rid of the use of linkname with almost no impact on performance.

I used this trick when preparing otter v2, as otter needs to store a lot of time.Time and time.Now is often too slow for the otter's needs.

Here are the benchmark results, which show that time.Since is actually equal to nanotime.

goos: darwin
goarch: arm64
pkg: github.com/maypok86/otter/v2/internal/clock
BenchmarkTimeNow
BenchmarkTimeNow-10     	42185438	        34.51 ns/op	       0 B/op	       0 allocs/op
BenchmarkNanotime
BenchmarkNanotime-10    	604727961	         1.920 ns/op	       0 B/op	       0 allocs/op
BenchmarkTimeSince
BenchmarkTimeSince-10       	549684618	         2.055 ns/op	       0 B/op	       0 allocs/op
PASS

@jackc jackc merged commit 56ab1e8 into jackc:master Sep 9, 2024
2 checks passed
@jackc
Copy link
Owner

jackc commented Sep 9, 2024

LGTM

@maypok86 maypok86 deleted the remove-linkname branch September 9, 2024 12:38
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.

3 participants