{"action":"closed","issue":{"url":"https://api.github.com/repos/ReactiveX/RxJava/issues/5825","repository_url":"https://api.github.com/repos/ReactiveX/RxJava","labels_url":"https://api.github.com/repos/ReactiveX/RxJava/issues/5825/labels{/name}","comments_url":"https://api.github.com/repos/ReactiveX/RxJava/issues/5825/comments","events_url":"https://api.github.com/repos/ReactiveX/RxJava/issues/5825/events","html_url":"https://github.com/ReactiveX/RxJava/issues/5825","id":292647786,"number":5825,"title":"2.x A question about the efficiency of processor sub classes implementation","user":{"login":"fanzhengchen","id":16400063,"avatar_url":"https://avatars3.githubusercontent.com/u/16400063?v=4","gravatar_id":"","url":"https://api.github.com/users/fanzhengchen","html_url":"https://github.com/fanzhengchen","followers_url":"https://api.github.com/users/fanzhengchen/followers","following_url":"https://api.github.com/users/fanzhengchen/following{/other_user}","gists_url":"https://api.github.com/users/fanzhengchen/gists{/gist_id}","starred_url":"https://api.github.com/users/fanzhengchen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fanzhengchen/subscriptions","organizations_url":"https://api.github.com/users/fanzhengchen/orgs","repos_url":"https://api.github.com/users/fanzhengchen/repos","events_url":"https://api.github.com/users/fanzhengchen/events{/privacy}","received_events_url":"https://api.github.com/users/fanzhengchen/received_events","type":"User","site_admin":false},"labels":[{"id":480313802,"url":"https://api.github.com/repos/ReactiveX/RxJava/labels/2.x","name":"2.x","color":"af40af","default":false},{"id":24234455,"url":"https://api.github.com/repos/ReactiveX/RxJava/labels/Question","name":"Question","color":"cc317c","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-01-30T04:15:12Z","updated_at":"2018-02-07T19:31:10Z","closed_at":"2018-02-07T19:31:10Z","author_association":"NONE","body":"I think the implementation of processor such as PublishProcessor could be improved.\r\nFor example of [PublishProcessor](https://github.com/ReactiveX/RxJava/blob/2.x/src/main/java/io/reactivex/processors/PublishProcessor.java)\r\n  2.x\r\n```java\r\nboolean add(PublishSubscription<T> ps) {\r\n        for (;;) {\r\n            PublishSubscription<T>[] a = subscribers.get();\r\n            if (a == TERMINATED) {\r\n                return false;\r\n            }\r\n\r\n            int n = a.length;\r\n            @SuppressWarnings(\"unchecked\")\r\n            PublishSubscription<T>[] b = new PublishSubscription[n + 1];\r\n            System.arraycopy(a, 0, b, 0, n);\r\n            b[n] = ps;\r\n\r\n            if (subscribers.compareAndSet(a, b)) {\r\n                return true;\r\n            }\r\n        }\r\n    }\r\n```\r\nwe apply for a new array and copy, it may fail when it runs with multiple threads, it would be a waste of computational resource when operate the array. I think **persistent data structure** would work better, especially for this assigning variable with multiple threads, what do you think?\r\n "}}
{"actor":{"display_login":"akarnokd"}}