{"action":"created","issue":{"url":"https://api.github.com/repos/python-attrs/attrs/issues/261","repository_url":"https://api.github.com/repos/python-attrs/attrs","labels_url":"https://api.github.com/repos/python-attrs/attrs/issues/261/labels{/name}","comments_url":"https://api.github.com/repos/python-attrs/attrs/issues/261/comments","events_url":"https://api.github.com/repos/python-attrs/attrs/issues/261/events","html_url":"https://github.com/python-attrs/attrs/issues/261","id":263625814,"number":261,"title":"Performance issues with hashing attrs objects","user":{"login":"DRMacIver","id":28623,"avatar_url":"https://avatars0.githubusercontent.com/u/28623?v=4","gravatar_id":"","url":"https://api.github.com/users/DRMacIver","html_url":"https://github.com/DRMacIver","followers_url":"https://api.github.com/users/DRMacIver/followers","following_url":"https://api.github.com/users/DRMacIver/following{/other_user}","gists_url":"https://api.github.com/users/DRMacIver/gists{/gist_id}","starred_url":"https://api.github.com/users/DRMacIver/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DRMacIver/subscriptions","organizations_url":"https://api.github.com/users/DRMacIver/orgs","repos_url":"https://api.github.com/users/DRMacIver/repos","events_url":"https://api.github.com/users/DRMacIver/events{/privacy}","received_events_url":"https://api.github.com/users/DRMacIver/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":14,"created_at":"2017-10-07T08:21:34Z","updated_at":"2018-02-01T15:07:24Z","closed_at":"2018-02-01T09:50:14Z","author_association":"NONE","body":"Backstory: I got a bug about a performance regression reported in Hypothesis ( https://github.com/HypothesisWorks/hypothesis-python/issues/919 ) and in the profiling data in the linked issue, the majority of the extra time (10 out of 13 seconds) is in attrs hashing.\r\n\r\nThis makes sense, as the enclosing method where most of the time is being spent does a *lot* of hashing of attrs objects, but it was still a bit surprising that it was this slow.\r\n\r\nThe class being hashed looks as follows:\r\n\r\n```python\r\n@attr.s(slots=True, frozen=True)\r\nclass Arc(object):\r\n    filename = attr.ib()\r\n    source = attr.ib()\r\n    target = attr.ib()\r\n```\r\n\r\nI have worked around this problem by now by removing attrs from this class and memoizing creation of it so that all value equal objects are reference equal, which is a bit more of an extreme solution than I expect attrs to support, but means that this bug is in no way critical for me as attrs will no longer be on the hot path of this code. It will probably however limit attrs uptake inside Hypothesis for now (I am likely to add a bunch more classes with a similar usage pattern and now will probably follow the pattern of the workaround I used here rather than using attrs).\r\n\r\nThe obvious two things that attrs could do to help are:\r\n\r\n* Have faster hashing. Almost all of that hashing time is in `_attrs_to_tuple`. Not creating these intermediate tuples (or creating them faster somehow) might be a significant win here.\r\n* Add support for caching the hash on the object. In my usage pattern the same objects were being hashed over and over again, and paying the hashing cost each time."},"comment":{"url":"https://api.github.com/repos/python-attrs/attrs/issues/comments/362293806","html_url":"https://github.com/python-attrs/attrs/issues/261#issuecomment-362293806","issue_url":"https://api.github.com/repos/python-attrs/attrs/issues/261","id":362293806,"user":{"login":"DRMacIver","id":28623,"avatar_url":"https://avatars0.githubusercontent.com/u/28623?v=4","gravatar_id":"","url":"https://api.github.com/users/DRMacIver","html_url":"https://github.com/DRMacIver","followers_url":"https://api.github.com/users/DRMacIver/followers","following_url":"https://api.github.com/users/DRMacIver/following{/other_user}","gists_url":"https://api.github.com/users/DRMacIver/gists{/gist_id}","starred_url":"https://api.github.com/users/DRMacIver/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DRMacIver/subscriptions","organizations_url":"https://api.github.com/users/DRMacIver/orgs","repos_url":"https://api.github.com/users/DRMacIver/repos","events_url":"https://api.github.com/users/DRMacIver/events{/privacy}","received_events_url":"https://api.github.com/users/DRMacIver/received_events","type":"User","site_admin":false},"created_at":"2018-02-01T15:07:24Z","updated_at":"2018-02-01T15:07:24Z","author_association":"NONE","body":"> I’m gonna interpret the lack of feedback as that the issue is at least roughly resolved.\r\n\r\nSorry about that. I don't have a convenient way to benchmark this as I ended up taking all of this code down a different route where it no longer really makes sense as an attrs benchmark. If you consider it fixed I'm happy, as I'm no longer affected by it either way, and if I run into problems here in future I'll reopen."}}
{"actor":{"display_login":"DRMacIver"}}