Caliburn.Micro icon indicating copy to clipboard operation
Caliburn.Micro copied to clipboard

Use stringbuilder instead of adding to string

Open vb2ae opened this issue 2 years ago • 4 comments

Change Viewmodelbinder to use a StringBuilder to improve performance

if (MessageBinder.SpecialValues.ContainsKey(specialValue))
                            paramName = specialValue;
                           message += paramName + ",";

Tracking issue for:

  • [ ] https://github.com/Caliburn-Micro/Caliburn.Micro/security/code-scanning/87

vb2ae avatar Oct 08 '23 12:10 vb2ae

Hi, @vb2ae. I've committed a change concerning this issue here. If you find this version satisfactory, I can create a PR.

Dennis40816 avatar Oct 11 '23 17:10 Dennis40816

Additionally, based on BenchmarkDotnet, I conducted a simple assessment on whether to use StringBuilder. I found that for methods with fewer than 3 parameters, the original method seems to have better performance in my environment. You can view the evaluation results on this page. Feel free to take a look if you're interested.

Dennis40816 avatar Oct 11 '23 17:10 Dennis40816

The code looks good. 'The report you did is awesome. I will have to think about it. I also was thinking since this code runs on a phone we need to worry about memory usage because strings are immutable.

vb2ae avatar Oct 12 '23 11:10 vb2ae

Thank you for your positive feedback. If there are further suggestions down the line, I'd be honored to continue making efforts to address them.

Dennis40816 avatar Oct 12 '23 13:10 Dennis40816