Open
Description
According to a profiling data from a large number of servers at Google, time.Time.Sub
is within the top 150 functions by CPU time. The current implementation of Sub
is not inlineable. The logic for Sub
is not particularly complicated and I believe it can be made to be inlined with some love.
Metadata
Metadata
Assignees
Type
Projects
Relationships
Development
No branches or pull requests
Activity
[-]time: optimize time.Time.Sub[/-][+]time: optimize time.Time.Sub and time.Time.Since[/+]dsnet commentedon Nov 8, 2016
time.Since
is also a hot function. It usesSub
internally. Unfortunately, it can't be inlined since it makes a call toruntime.now
.[-]time: optimize time.Time.Sub and time.Time.Since[/-][+]time: optimize time.Time.Sub and time.Since[/+]josharian commentedon Nov 9, 2016
Oddly, looking at the output of
-gcflags="-m -m"
, I don't seeTime.Sub
listed at all, either as inlineable or non-inlineable.gopherbot commentedon Nov 9, 2016
CL https://golang.org/cl/32971 mentions this issue.
josharian commentedon Nov 9, 2016
Time.Sub
currently has an inlining cost of 116, well above the current inlining threshold of 80. Some minor fiddling around (below) brings it down to 111. I don't see this happening without some compiler fixes; that is #17566. (Note that Time.Sub currently compiles into 227 bytes of code, about the same as two appends.)dsnet commentedon Nov 9, 2016
I looked at this earlier today, and I am suspicious of the current overflow checking logic.
Sub
does overflow checking by checking thatu.Add(d).Equal(t)
, which initially seems legit, but it's kinda strange since theAdd
method itself does not do overflow checking. Thus, I find it strange that overflow checking is depending on a function that is not overflow safe.This is a version of
Sub
I came up with that is inlineable:On my machine, this version runs 3.2x faster.
cmd/compile: report more non-inlineable functions
bradfitz commentedon May 23, 2017
Sadly bumping this to Go 1.10.
16 remaining items