Skip to content

Performance Issue: InternetAddressList.TryParse Slow with Large Recipient Lists #1106

@kamilpastwa

Description

@kamilpastwa

Describe the problem
The InternetAddressList.TryParse method hangs for an extended time when processing a large number of input data. For example, when parsing a list of 100,000 participants, the method takes more than 10 minutes to complete.

Here's how the method scales with the size of the input data:
image

Platform:

  • OS: Windows 10
  • .NET Runtime: CoreCLR
  • .NET Framework: .NET 6.0
  • MimeKit Version: 4.8.0

To Reproduce
Run this unit test:

[TestCase(100000)]
public void RsmfLotOfParticipantsTest(int participantsCount)
{
	// Arrange

	// Prepare recipients 
	StringBuilder recipientsStringBuilder = new ();
	for (int i = 0; i < participantsCount; i++)
	{
		recipientsStringBuilder.Append($"\"Fake User{i+1} <>\"");
		if (i < participantsCount - 1)
		{
			recipientsStringBuilder.Append(", ");
		}
	}
	string recipients = recipientsStringBuilder.ToString();

	// Act
	var stopwatch = Stopwatch.StartNew();
	bool result = InternetAddressList.TryParse(new ParserOptions { AllowAddressesWithoutDomain = true }, recipients, out InternetAddressList addressList);

	// Assert
	Assert.IsTrue(result);
	Assert.AreEqual(addressList.Count, participantsCount);
	Console.WriteLine($"{participantsCount};{stopwatch.Elapsed}");
}

Expected behavior
The method should handle large input data efficiently without significant delays.

Additional context
I am attaching the original test file that led me to this problem:
100k-participants.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    performanceImprovements to speed or memory consumption

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions