Bug #64012 CommandText property set method performance improvement
Submitted: 12 Jan 2012 14:34 Modified: 8 Mar 2012 19:22
Reporter: Kim Christensen Email Updates:
Status: Closed Impact on me:
Category:Connector / NET Severity:S5 (Performance)
Version: OS:Windows (7 64-bit)
Assigned to: Fernando Gonzalez.Sanchez CPU Architecture:Any

[12 Jan 2012 14:34] Kim Christensen
Performance when setting the CommandText property on the MySqlCommand class, can be improved by factor 100, on a very large number of queries.

How to repeat:
const string Test = "hdasjkhdasjkhdasdhjsdadasddjkasklædaklæsdlækasdkklæasdklæasd  fdfsdfsd dsa8() default";
Stopwatch stopwatch = new Stopwatch();
for (int i = 0; i < 10000000; i++)
	Test.EndsWith("default", StringComparison.Ordinal);

Console.WriteLine("Took " + stopwatch.Elapsed);

for (int i = 0; i < 10000000; i++)

Console.WriteLine("Took " + stopwatch.Elapsed);

My output are:
Took 00:00:00.2348015
Took 00:00:20.3238133

Suggested fix:
This can be done by changing the line 131 in MySqlCommand.cs:
if (cmdText != null && cmdText.EndsWith("DEFAULT VALUES"))
with the following:
if (cmdText != null && cmdText.EndsWith("DEFAULT VALUES", StringComparison.Ordinal))

The reason for this is that EndsWith by default compares using the current culture, which apparently are very slow compared to StringComparison.Ordinal.
[8 Mar 2012 19:22] Fernando Gonzalez.Sanchez
Thank you for your bug report. This issue has already been fixed in the latest released version of that product, which you can download at


This has been fixed and released in 6.5.4 and will be released in 6.3.9 & 6.4.5.
[12 Apr 2012 1:37] John Russell
Added to changelog for 6.3.9, 6.4.5, 6.5.3: 

The performance when setting the CommandText property on the
MySqlCommand class was improved by enhancing the efficiency of a
string comparison operation.