Click here to Skip to main content
15,927,947 members
Home / Discussions / C#
   

C#

 
AnswerRe: Need Help with Optimizing My C# Code for Better Performance Pin
OriginalGriff31-May-24 2:39
mveOriginalGriff31-May-24 2:39 
AnswerRe: Need Help with Optimizing My C# Code for Better Performance Pin
PIEBALDconsult31-May-24 2:52
mvePIEBALDconsult31-May-24 2:52 
AnswerRe: Need Help with Optimizing My C# Code for Better Performance Pin
Dave Kreskowiak31-May-24 12:39
mveDave Kreskowiak31-May-24 12:39 
GeneralRe: Need Help with Optimizing My C# Code for Better Performance Pin
trønderen8-Jun-24 5:22
trønderen8-Jun-24 5:22 
GeneralRe: Need Help with Optimizing My C# Code for Better Performance Pin
Dave Kreskowiak8-Jun-24 6:42
mveDave Kreskowiak8-Jun-24 6:42 
GeneralRe: Need Help with Optimizing My C# Code for Better Performance Pin
trønderen9-Jun-24 3:35
trønderen9-Jun-24 3:35 
GeneralRe: Need Help with Optimizing My C# Code for Better Performance Pin
Dave Kreskowiak9-Jun-24 4:08
mveDave Kreskowiak9-Jun-24 4:08 
AnswerRe: Need Help with Optimizing My C# Code for Better Performance Pin
Rob Philpott4-Jun-24 2:00
Rob Philpott4-Jun-24 2:00 
A bit late to the party, but here are a few thoughts.

String manipulations are as you say possibly the most likely bottleneck. Strings are immutable in C# (they don't change), so if you concatenate two strings it involves copying the data from both of them into a new string. If you're doing this in a tight loop there's going to a lots of work (and garbage collection) involved. For building up strings, StringBuilder is the class of choice, and for substrings etc. you could look at Span<char>s (C# - All About Span: Exploring a New .NET Mainstay | Microsoft Learn.

If your files are large, take a streaming approach. For instance File.ReadAllLines() loads everything into memory where as File.ReadLines() returns an iterator where you just deal with the current line. Reading a massive file into memory often isn't a great idea.

With those in place, the only other thing I can think of is pipelining. Have one thread read the input file and present records via a queue to a processing stage which processes them and then submits them via a queue to a writing stage. All these stages can run concurrently. TPL dataflow is the thing for this.

Finally, if you are using Parallel processing for nested loops, make sure you do it on the outer loop. There is overhead in parallelising work and you get better performance that way.

It's all rather difficult to say without seeing the code!
Regards,
Rob Philpott.

GeneralRe: Need Help with Optimizing My C# Code for Better Performance Pin
jochance7-Jun-24 2:28
jochance7-Jun-24 2:28 
AnswerRe: Need Help with Optimizing My C# Code for Better Performance Pin
jschell7-Jun-24 12:41
jschell7-Jun-24 12:41 
Questionhow to get repository user list and and user group from Azure DevOps Pin
arjunmca28-May-24 21:49
arjunmca28-May-24 21:49 
AnswerRe: how to get repository user list and and user group from Azure DevOps Pin
OriginalGriff28-May-24 22:27
mveOriginalGriff28-May-24 22:27 
GeneralRe: how to get repository user list and and user group from Azure DevOps Pin
trønderen29-May-24 5:21
trønderen29-May-24 5:21 
Questiontelegram client api to download video files and/or telegram video link Pin
Tony Germanos28-May-24 6:59
Tony Germanos28-May-24 6:59 
AnswerRe: telegram client api to download video files and/or telegram video link Pin
OriginalGriff28-May-24 18:19
mveOriginalGriff28-May-24 18:19 
GeneralAD Sync Manager - a free tool to easily monitor and manage your AD to Azure AD sync Pin
TheITApprentice21-May-24 18:29
TheITApprentice21-May-24 18:29 
GeneralRe: AD Sync Manager - a free tool to easily monitor and manage your AD to Azure AD sync Pin
OriginalGriff21-May-24 18:30
mveOriginalGriff21-May-24 18:30 
QuestionHow to convert XML to text file Pin
Member 1211605220-May-24 19:37
Member 1211605220-May-24 19:37 
AnswerRe: How to convert XML to text file Pin
Richard Deeming20-May-24 21:32
mveRichard Deeming20-May-24 21:32 
AnswerRe: How to convert XML to text file Pin
trønderen21-May-24 4:43
trønderen21-May-24 4:43 
AnswerRe: How to convert XML to text file Pin
jschell21-May-24 12:27
jschell21-May-24 12:27 
AnswerRe: How to convert XML to text file Pin
OriginalGriff21-May-24 19:02
mveOriginalGriff21-May-24 19:02 
QuestionWhere to hand over the instance of my plugin dll class to another class Pin
AtaChris18-May-24 8:34
AtaChris18-May-24 8:34 
AnswerRe: Where to hand over the instance of my plugin dll class to another class Pin
OriginalGriff18-May-24 20:20
mveOriginalGriff18-May-24 20:20 
GeneralRe: Where to hand over the instance of my plugin dll class to another class Pin
Dave Kreskowiak19-May-24 5:02
mveDave Kreskowiak19-May-24 5:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.