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

runtime: heavy time.Now usage cause taskgated to consume lots of cpu #15290

davecheney opened this Issue Apr 14, 2016 · 1 comment


None yet
4 participants

davecheney commented Apr 14, 2016

Please answer these questions before submitting your issue. Thanks!

  1. What version of Go are you using (go version)?

go version devel +bd72497 Mon Apr 11 01:52:10 2016 +0000 darwin/amd64

  1. What operating system and processor architecture are you using (go env)?


  1. What did you do?
    Run this program
package main

import (

func main() {
        t1 := time.Now().Add(-1 * time.Second) // ensure there is no collision on first iteration
        for {
                t2 := time.Now()
                d := t2.Sub(t1)
                if d == 0 {
                        fmt.Println("collision at", t2)
                t1 = t2
  1. What did you expect to see?

This program should cause 100% cpu usage.

  1. What did you see instead?

The program causes 100% cpu usage, but taskgated is also heavily used , around 20% on my system.

Reports that taskgated is responsible for implemting the mach task_for_pid syscall (?), so it looks like we're calling this syscall many times, we should probably not do that and cache the task port once per process.


This comment has been minimized.


AlekSi commented Apr 14, 2016

Can't verify it on OS X 10.11.4 with both 1.6.1 and devel +285e786. taskgated is nowhere near the top, dtruss doesn't show anything unexpected.

@bradfitz bradfitz added this to the Unplanned milestone Apr 14, 2016

@josharian josharian changed the title from Heavy time.Now usage cause taskgated to consume lots of cpu to runtime: heavy time.Now usage cause taskgated to consume lots of cpu Apr 14, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment