Skip to content

errors: performance regression in New #30468

Closed
@bcmills

Description

@bcmills

CL 163557 added a call to runtime.Callers in the path of errors.New, which has now become a bottleneck in cmd/go initialization (see #29382 (comment)).

While I understand the desire to capture stack information in errors (#29934), errors.New in particular used to be an inexpensive operation, and it needs to remain inexpensive. Ideally, errors.New(someConstant) should be fully inlined: the caller PC is known at link-time, and that's all we should need in order to produce a reasonable error frame.

Activity

added
NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.
on Feb 28, 2019
added this to the Go1.13 milestone on Feb 28, 2019
bcmills

bcmills commented on Feb 28, 2019

@bcmills
ContributorAuthor

Marking as release-blocker for 1.13: at the very least, we should investigate the impact of this regression in other low-latency programs and make an explicit decision about whether the regression is an acceptable cost.

bcmills

bcmills commented on Feb 28, 2019

@bcmills
ContributorAuthor
mvdan

mvdan commented on Feb 28, 2019

@mvdan
Member

Thanks for filing this issue. I actually think runtime.Callers is reasonable if the errors.New happens outside of a global var declaration. But it's even better if the cost is always minimal.

neild

neild commented on Feb 28, 2019

@neild
Contributor

If it proves infeasible to make it sufficiently fast, dropping stack frames from errors.New and only adding them in fmt.Errorf could be an option. We should first see if the cost can be made minimal, though.

mvdan

mvdan commented on Feb 28, 2019

@mvdan
Member

I'm not sure that making errors.New do less work is ideal; it could lead to premature optimizations like "avoid fmt.Errorf for the sake of performance", even if the uses are outside of global variables.

It's also possibly reasonable to use fmt.Errorf for globals or in init, I'd imagine.

gopherbot

gopherbot commented on Mar 13, 2019

@gopherbot
Contributor

Change https://golang.org/cl/167401 mentions this issue: errors: improve performance of New

gopherbot

gopherbot commented on Mar 13, 2019

@gopherbot
Contributor

Change https://golang.org/cl/167400 mentions this issue: errors: record only single frame

dmitshur

dmitshur commented on May 16, 2019

@dmitshur
Member

This was fixed via CL 176997, which reverted the change that was causing this issue. /cc @andybons

locked and limited conversation to collaborators on May 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @neild@dmitshur@mvdan@bcmills@gopherbot

        Issue actions

          errors: performance regression in New · Issue #30468 · golang/go