Skip to content

[performance] fmt.Sprintf gets called for every single log line #1378

@frankjkelly

Description

@frankjkelly

Noticed this during a flamegraph analysis of our code

Image

Looks like fmt.Sprintf is pretty expensive for CPU usage? Especially for Debug logging.

func (s *slogWrapper) Debugf(format string, args ...any) {
s.logger.Debug(fmt.Sprintf(format, args...))
}
func (s *slogWrapper) Infof(format string, args ...any) {
s.logger.Info(fmt.Sprintf(format, args...))
}
func (s *slogWrapper) Warnf(format string, args ...any) {
s.logger.Warn(fmt.Sprintf(format, args...))
}
func (s *slogWrapper) Errorf(format string, args ...any) {
s.logger.Error(fmt.Sprintf(format, args...))
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions