So from the profiler run, almost all of our time is spent in removing WorkerRefs from their nsTAutoObserverArray. This makes sense because we're adding 50k or 200k ThreadSafeWorkerRefs quickly because we're just appending them to an array, but the underlying operation completions that release the worker refs are FIFO so then as we remove them we are basically the ~first element in an array of 50k items 50k times which doesn't perform amazingly. Because we absolutely expect WorkerRefs to be removed when notifying them (and potentially not just the one we're notifying; pathological removal is possible), we would probably want to change to [mozilla::SafeDoublyLinkedList](https://searchfox.org/mozilla-central/rev/c85c168374483a3c37aab49d7f587ea74a516492/mfbt/DoublyLinkedList.h#405-415). (Compare with std::list or the normal [mozilla::DoublyLinkedList](https://searchfox.org/mozilla-central/rev/c85c168374483a3c37aab49d7f587ea74a516492/mfbt/DoublyLinkedList.h#104-111) which invalidate iterators referencing deleted items because iterators aren't tracked and can't be updated.
Bug 1982510 Comment 5 Edit History
Note: The actual edited comment in the bug view page will always show the original commenter’s name and original timestamp.
So from the profiler run, almost all of our time is spent in removing WorkerRefs from their nsTAutoObserverArray. This makes sense because we're adding 50k or 200k ThreadSafeWorkerRefs quickly because we're just appending them to an array, but the underlying operation completions that release the worker refs are FIFO so then as we remove them we are removing the ~first element in an array of 50k items 50k times which doesn't perform amazingly. Because we absolutely expect WorkerRefs to be removed when notifying them (and potentially not just the one we're notifying; pathological removal is possible), we would probably want to change to [mozilla::SafeDoublyLinkedList](https://searchfox.org/mozilla-central/rev/c85c168374483a3c37aab49d7f587ea74a516492/mfbt/DoublyLinkedList.h#405-415). (Compare with std::list or the normal [mozilla::DoublyLinkedList](https://searchfox.org/mozilla-central/rev/c85c168374483a3c37aab49d7f587ea74a516492/mfbt/DoublyLinkedList.h#104-111) which invalidate iterators referencing deleted items because iterators aren't tracked and can't be updated.
So from the profiler run, almost all of our time is spent in removing WorkerRefs from their nsTAutoObserverArray. This makes sense because we're adding 50k or 200k ThreadSafeWorkerRefs quickly because we're just appending them to an array, but the underlying operation completions that release the worker refs are FIFO so then as we remove them we are removing the ~first element in an array of 50k items 50k times which doesn't perform amazingly. Because we absolutely expect WorkerRefs to be removed when notifying them (and potentially not just the one we're notifying; pathological removal is possible), we would probably want to change to [mozilla::SafeDoublyLinkedList](https://searchfox.org/mozilla-central/rev/c85c168374483a3c37aab49d7f587ea74a516492/mfbt/DoublyLinkedList.h#405-415). (Compare with std::list or the normal [mozilla::DoublyLinkedList](https://searchfox.org/mozilla-central/rev/c85c168374483a3c37aab49d7f587ea74a516492/mfbt/DoublyLinkedList.h#104-111) which invalidate iterators referencing deleted items because iterators aren't tracked and can't be updated.)