Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6801465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:06:13+00:00 2026-05-26T19:06:13+00:00

During last week I received some code and was asked to improve the performance.

  • 0

During last week I received some code and was asked to improve the performance. So started with the job, but soon I saw that they use a lot of HashSet<T> objects, to store big collections of objects (between 10000 to more than 100000 objects). In the code they use HashSet<T> for performance reasons.

The only thing that they do is populate the HashSet with objects and then us some Linq to execute queries between multiple collections. Most of the queries are joining 1 or n HashSet, or retrieving specific object(s) from the collection with First() or Where().

I’m wondering if we gain any performance advantage compared to a normal List<T>? Because all the Linq extension methods they use in code are written for IEnumerable<T>.

On the internet a lot of articles say that List would be faster, but some say that HashSet handles huge collections much better than List.

Hope that someone can give me more advice.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T19:06:13+00:00Added an answer on May 26, 2026 at 7:06 pm

    If you use just LINQ queries, you don’t get any perf advantage, since you are just enumerating through the entire collection. In fact, it could be that List<T> is better performance because of the contiguous internal storage.

    To get the perf benefit of a HashSet<T>, you need to use the ISet<T> methods, ideally with another HashSet<T> since, looking at the code, it is optimized for this case. Further, operations will only be faster which take advantage of the member objects’ hash codes, like equality testing, since the performance of HashSet<T> is based on the O(1) performance characteristic of hash lookups. Operations which don’t make use of the members’ hash codes, like filtering on a member property vs. the members themselves, will need to be an O(N) operation, making it the same as a List<T>.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I spent a good portion of time last week working on serialization. During that
During the last years I always thought that in Java, Reflection is widely used
I've been at this for several times during the last couple of months, but
I'm going to start a new project with WPF, during last week I read
I've been playing with redis (and add some fun with it) during the last
During the last few days I've gained some information about memory allocators other than
During my last project I noticed, that it is very convenient, to include design
I have faced this problem quite often during the last couple of months, during
During a discussion about security, a developer on my team asked if there was
During a typical day programming, I implement functions in a way that I would

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.