Skip to content

Conversation

akarnokd
Copy link
Collaborator

When ElementAt finds an item, it disposes the upstream, however, the upstream may still emit an OnCompleted if it is unable to detect this dispose call (or ignores it). In this case, the ElementAt's OnCompleted gets invoked which creates an exception that gets thrown away as the base observer is already the no-op observer, wasting resources creating the stacktrace in the process.

I don't know how to verify this via unit test, but this extra call can be seen when placing a breakpoint in ElementAt's OnCompleted method and running this flow:

Observable.Return(1).ElementAt(0).Subscribe();

@danielcweber
Copy link
Collaborator

Just to clarify, a stacktrace isn't created until the exception is actually thrown.

@danielcweber danielcweber merged commit 421e2a2 into dotnet:master Jun 28, 2018
@akarnokd akarnokd deleted the ElementAtImprovements branch June 28, 2018 16:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants