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

  • Home
  • SEARCH
  • 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 338281
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:24:53+00:00 2026-05-12T10:24:53+00:00

We were trying to sort a collection of FileInfo objects in .NET. We implemented

  • 0

We were trying to sort a collection of FileInfo objects in .NET. We implemented our IComparer to ensure that FileInfo objects were sorted based on our criteria. We then noticed that performance of sorting the FileInfo objects was many times slower than just ints. On a hunch (and remembering how references work in C) we were able to improve performance by using local variables to limit the number of times we referenced FileInfo properties.

My idea was that local variables would be faster to access than properties on objects. I think that this makes sense in the world of unmanaged code, where I can actually picture how the stack works and how values are referenced. However, I know the world of managed code can be more complicated under the covers. My question is: Can these basic ideas of memory management and program flow in un-managed code be generally projected into the world of managed code?

Eventually with the help from KeeperOfTheSoul, we were able to track this down to how we were mocking the FileInfo object. For that reason, I have added a RhinoMock tag to this quesiton.

  • 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-12T10:24:54+00:00Added an answer on May 12, 2026 at 10:24 am

    There shouldn’t really be a speed difference between sorting a value type compared to a reference type except for the implementation of the comparison method. If I implemented a comparison method that used sin then the ints would sort slowly as well.

    Accessing a property does involve a method call, whilst accessing a local variable, either the value is directly on the stack or already in a register. However, simple properties can be optimized by the JIT to provide something similar to inlining.

    In this case I think the problem is that FileInfo can require a file system read to get the properties value, and if FileInfo doesn’t internally cache the value it could end up performing this read repeatedly.

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

Sidebar

Related Questions

I'm trying to write a function that would sort a collection of objects. Since
I have a C# list collection that I'm trying to sort. The strings that
I'm trying to sort through a collection of DeepZoom sub-images based on arbitrary data
Trying to sort this array of objects according to (1) depth and (2) weight,
I'm trying to sort a multidimensional array in objective-c i know that i can
I've been trying unsuccessfully to filter a collection of child objects for a few
I'm having a logic problem trying to return a collection of objects from a
I'm trying to sort a collection derived from CollectionViewSource, which simply has SortDescriptions for
I'm trying to sort a collection by attribute_id . I thought it would be
Am trying to sort via a certain value in the function, Collection users =

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.