{"action":"created","issue":{"url":"https://api.github.com/repos/javaslang/javaslang/issues/578","labels_url":"https://api.github.com/repos/javaslang/javaslang/issues/578/labels{/name}","comments_url":"https://api.github.com/repos/javaslang/javaslang/issues/578/comments","events_url":"https://api.github.com/repos/javaslang/javaslang/issues/578/events","html_url":"https://github.com/javaslang/javaslang/issues/578","id":105313713,"number":578,"title":"Remove optimizations that rely on HashArrayMappedTrie.size()","user":{"login":"danieldietrich","id":743833,"avatar_url":"https://avatars.githubusercontent.com/u/743833?v=3","gravatar_id":"","url":"https://api.github.com/users/danieldietrich","html_url":"https://github.com/danieldietrich","followers_url":"https://api.github.com/users/danieldietrich/followers","following_url":"https://api.github.com/users/danieldietrich/following{/other_user}","gists_url":"https://api.github.com/users/danieldietrich/gists{/gist_id}","starred_url":"https://api.github.com/users/danieldietrich/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danieldietrich/subscriptions","organizations_url":"https://api.github.com/users/danieldietrich/orgs","repos_url":"https://api.github.com/users/danieldietrich/repos","events_url":"https://api.github.com/users/danieldietrich/events{/privacy}","received_events_url":"https://api.github.com/users/danieldietrich/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/javaslang/javaslang/labels/design/refactoring","name":"design/refactoring","color":"fbca04"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/javaslang/javaslang/milestones/18","html_url":"https://github.com/javaslang/javaslang/milestones/2.0.0","labels_url":"https://api.github.com/repos/javaslang/javaslang/milestones/18/labels","id":1091674,"number":18,"title":"2.0.0","description":"","creator":{"login":"danieldietrich","id":743833,"avatar_url":"https://avatars.githubusercontent.com/u/743833?v=3","gravatar_id":"","url":"https://api.github.com/users/danieldietrich","html_url":"https://github.com/danieldietrich","followers_url":"https://api.github.com/users/danieldietrich/followers","following_url":"https://api.github.com/users/danieldietrich/following{/other_user}","gists_url":"https://api.github.com/users/danieldietrich/gists{/gist_id}","starred_url":"https://api.github.com/users/danieldietrich/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danieldietrich/subscriptions","organizations_url":"https://api.github.com/users/danieldietrich/orgs","repos_url":"https://api.github.com/users/danieldietrich/repos","events_url":"https://api.github.com/users/danieldietrich/events{/privacy}","received_events_url":"https://api.github.com/users/danieldietrich/received_events","type":"User","site_admin":false},"open_issues":15,"closed_issues":137,"state":"open","created_at":"2015-04-30T20:29:59Z","updated_at":"2015-09-08T18:59:27Z","due_on":null,"closed_at":null},"comments":3,"created_at":"2015-09-08T06:54:19Z","updated_at":"2015-09-08T19:15:32Z","closed_at":null,"body":"We use size() to determine if the newly created collections has the same size as the current collection. To save mem, we return the current instance if sizes are equal.\r\n\r\nBecause HAMT.size() is now O(n) (at least once, if lazy evaluated), then cannot use this optimization any more.\r\n\r\nCandidates to check are HashSet, HashMap and Vector. Maybe also other collections..."},"comment":{"url":"https://api.github.com/repos/javaslang/javaslang/issues/comments/138674055","html_url":"https://github.com/javaslang/javaslang/issues/578#issuecomment-138674055","issue_url":"https://api.github.com/repos/javaslang/javaslang/issues/578","id":138674055,"user":{"login":"danieldietrich","id":743833,"avatar_url":"https://avatars.githubusercontent.com/u/743833?v=3","gravatar_id":"","url":"https://api.github.com/users/danieldietrich","html_url":"https://github.com/danieldietrich","followers_url":"https://api.github.com/users/danieldietrich/followers","following_url":"https://api.github.com/users/danieldietrich/following{/other_user}","gists_url":"https://api.github.com/users/danieldietrich/gists{/gist_id}","starred_url":"https://api.github.com/users/danieldietrich/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danieldietrich/subscriptions","organizations_url":"https://api.github.com/users/danieldietrich/orgs","repos_url":"https://api.github.com/users/danieldietrich/repos","events_url":"https://api.github.com/users/danieldietrich/events{/privacy}","received_events_url":"https://api.github.com/users/danieldietrich/received_events","type":"User","site_admin":false},"created_at":"2015-09-08T19:15:32Z","updated_at":"2015-09-08T19:15:32Z","body":"It can be - at the cost of computing the size at construction time, e.g. via `subNodes.map(AbstractNode::size).sum().intValue()`. But my performance measures showed, that this costs too much time.\r\n\r\nAn alternative is, that we add a lazy field `Lazy<Integer> size = ...`. But when we want to calculate the size of a big collection, we first have to calculcate (once) all these lazy values in O(n). Ok, we do it only once, but at the cost of extra garbage/memory.\r\n\r\nHaving *not* a Lazy length is not really a disadvantage. If we need the size in an app more than once, we can introduce a local var instead of having an instance variable, e.g.\r\n\r\n```java\r\nfinal int length = myMap.length(); // calculated once\r\n```\r\n\r\nLet's have a look at other languages."}}