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 8982935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:42:15+00:00 2026-06-15T20:42:15+00:00

I have a need to optimize a large apps that use linq extensively. Many

  • 0

I have a need to optimize a large apps that use linq extensively. Many of the linq statements create anonymous objects within the linq extension methods. An example :-

// custom sort order
var sortedData = data.OrderBy(x => (new List<string>() {"Orange", "Apple", "Pear" }).IndexOf(x.Name));
foreach (var d in sortedData) {
    ....

The problem is that a new List gets created for every iteration.

Is there a compiler flag I can set to get the compiler to do some static analysis and extract the loop invariant code to be outside of the loop?

  • 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-06-15T20:42:17+00:00Added an answer on June 15, 2026 at 8:42 pm

    I think many people got caught up in your order by example and missed your real question.

    No there is no simple tool built in to visual studio that can do this statically (without running the program). There are two tools that may help you out if you can run the program and execute the code in question (you do have unit tests that has 100% code coverage don’t you 😉 ). One is a profiler built in to Visual Studio, and one the other is the CLR profiler.

    I have never used the CLR profiler and it may just be a older version of what is in visual studio. The visual studio profiler can show you if a large number of objects are being created (Lists in your example) and see where in the code those objects are being created. It can also show you which lines of code are taking the longest to execute so you know where to focus your effort to speed up your program.

    If you have specific issues running the profiler I recommend opening a new question up on the issue,

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

Sidebar

Related Questions

I am have a lot of code that I need to optimize and make
I have a webpage that is taking way too long and need to optimize
I have need for a function pointer that takes two arguments and returns a
I have a need for two slightly different classes, that have the same members,
I have a large unsorted list of items. Some items are important and need
I have a large number of (>100k) relatively small files (1kb - 300kb) that
I have several large MyISAM tables (data file around 1.5 GB) which I need
I have a graph problem as follows and I need to optimize its execution
I have a very large list of items (~2 millions) that I want to
A lot of people have said that ArrayList.removeAll is really slow with large size

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.