Skip to content
This repository was archived by the owner on Jul 2, 2024. It is now read-only.

Clear out ElasticResponse large hits collection after done materializing.#94

Merged
damieng merged 1 commit into
masterfrom
perf-clearHitsList
Jan 4, 2017
Merged

Clear out ElasticResponse large hits collection after done materializing.#94
damieng merged 1 commit into
masterfrom
perf-clearHitsList

Conversation

@marcind

@marcind marcind commented May 21, 2016

Copy link
Copy Markdown
Contributor

A large enough hits list will end up getting allocated on the large object heap, which will pin all the result documents in memory longer than necessary.

This is one of the changes to address issues mentioned in #89

…ing.

A large enough hits list will end up getting allocated on the large object heap, which will pin all the result documents in memory longer than necessary.
if (response.hits != null)
{
var hits = response.hits.hits;
if (hits != null && hits.Capacity > 4096)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any harm in just always clearing the hits after materialization?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not. I guess zeroing out an array should be fairly well optimized in .net.

@damieng

damieng commented May 30, 2016

Copy link
Copy Markdown
Collaborator

The following change would probably be better for memory... but worse for perf (in ListHitsElasticMaterializer)

        internal static IEnumerable<T> Many<T>(List<Hit> hits, Func<Hit, object> projector)
        {
            while (hits.Count > 0)
            {
                var result = (T)projector(hits[0]);
                hits.RemoveAt(0);
                yield return result;
            }
        }

Thoughts?

@marcind

marcind commented Jun 8, 2016

Copy link
Copy Markdown
Contributor Author

Could probably write a quick app to compare, but my intuition tells me it'll be pretty bad since RemoveAt shifts all the remaining items to the left, so there's O(n^2) memory being moved around.

@damieng
damieng merged commit f771088 into master Jan 4, 2017
@damieng
damieng deleted the perf-clearHitsList branch January 4, 2017 16:49
@damieng
damieng restored the perf-clearHitsList branch January 4, 2017 16:52
@damieng
damieng deleted the perf-clearHitsList branch January 4, 2017 17:03
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants