{"action":"created","issue":{"url":"https://api.github.com/repos/prometheus/client_python/issues/256","repository_url":"https://api.github.com/repos/prometheus/client_python","labels_url":"https://api.github.com/repos/prometheus/client_python/issues/256/labels{/name}","comments_url":"https://api.github.com/repos/prometheus/client_python/issues/256/comments","events_url":"https://api.github.com/repos/prometheus/client_python/issues/256/events","html_url":"https://github.com/prometheus/client_python/pull/256","id":307189297,"number":256,"title":"Reduce unnecessary metric creation in loop","user":{"login":"umax","id":14619,"avatar_url":"https://avatars1.githubusercontent.com/u/14619?v=4","gravatar_id":"","url":"https://api.github.com/users/umax","html_url":"https://github.com/umax","followers_url":"https://api.github.com/users/umax/followers","following_url":"https://api.github.com/users/umax/following{/other_user}","gists_url":"https://api.github.com/users/umax/gists{/gist_id}","starred_url":"https://api.github.com/users/umax/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/umax/subscriptions","organizations_url":"https://api.github.com/users/umax/orgs","repos_url":"https://api.github.com/users/umax/repos","events_url":"https://api.github.com/users/umax/events{/privacy}","received_events_url":"https://api.github.com/users/umax/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-03-21T10:29:51Z","updated_at":"2018-03-21T10:47:13Z","closed_at":"2018-03-21T10:47:09Z","author_association":"CONTRIBUTOR","pull_request":{"url":"https://api.github.com/repos/prometheus/client_python/pulls/256","html_url":"https://github.com/prometheus/client_python/pull/256","diff_url":"https://github.com/prometheus/client_python/pull/256.diff","patch_url":"https://github.com/prometheus/client_python/pull/256.patch"},"body":"Hi!\r\n\r\nI will try to improve multiprocess metrics collections by a series of pull requests.\r\nThis one fixes unnecessary metric creation in loop.\r\n\r\nThe more correct way to use `dict.setdefault` is `result = dict.setdefault(key, value)`. In our case:\r\n\r\n```\r\nmetric = metrics.setdefault(metric_name, core.Metric(...))\r\n```\r\ninstead of\r\n```\r\nmetrics.setdefault(metric_name, core.Metric(...))\r\nmetric = metrics[metric_name]\r\n```\r\n\r\nBut the problem is that `core.Metric(...)` will be executed each time when **setdefault** method calls whether needed or not."},"comment":{"url":"https://api.github.com/repos/prometheus/client_python/issues/comments/374897153","html_url":"https://github.com/prometheus/client_python/pull/256#issuecomment-374897153","issue_url":"https://api.github.com/repos/prometheus/client_python/issues/256","id":374897153,"user":{"login":"brian-brazil","id":7115638,"avatar_url":"https://avatars0.githubusercontent.com/u/7115638?v=4","gravatar_id":"","url":"https://api.github.com/users/brian-brazil","html_url":"https://github.com/brian-brazil","followers_url":"https://api.github.com/users/brian-brazil/followers","following_url":"https://api.github.com/users/brian-brazil/following{/other_user}","gists_url":"https://api.github.com/users/brian-brazil/gists{/gist_id}","starred_url":"https://api.github.com/users/brian-brazil/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brian-brazil/subscriptions","organizations_url":"https://api.github.com/users/brian-brazil/orgs","repos_url":"https://api.github.com/users/brian-brazil/repos","events_url":"https://api.github.com/users/brian-brazil/events{/privacy}","received_events_url":"https://api.github.com/users/brian-brazil/received_events","type":"User","site_admin":false},"created_at":"2018-03-21T10:47:13Z","updated_at":"2018-03-21T10:47:13Z","author_association":"OWNER","body":"Thanks!"}}
{"actor":{"display_login":"brian-brazil"}}