Skip to content

Commit c4f3353

Browse files
committed
merged branch jimbojsb/master (PR swiftmailer#280)
This PR was merged into the master branch. Commits ------- 37372cd replace array_merge with manual iteration for performance Discussion ---------- Fix performance when tokenizing massive headers I made this update to fix a performance issue when using very large headers. The use case is SendGrid's bulk messaging API in which there can be many thousands of lines of JSON in one X-SMTPAPI header. array_merge() is known to be slow when dealing with arrays over about 100 items and being called repeatedly, because it's doing a key re-sort operation every time. This change, in my 1000 item example, made the processing that happens inside ->send() go from 2 minutes to 2 seconds.
2 parents 393b446 + 37372cd commit c4f3353

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

lib/classes/Swift/Mime/Headers/AbstractHeader.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -458,9 +458,11 @@ protected function toTokens($string = null)
458458

459459
//Generate atoms; split at all invisible boundaries followed by WSP
460460
foreach (preg_split('~(?=[ \t])~', $string) as $token) {
461-
$tokens = array_merge($tokens, $this->generateTokenLines($token));
461+
$newTokens = $this->generateTokenLines($token);
462+
foreach ($newTokens as $newToken) {
463+
$tokens[] = $newToken;
464+
}
462465
}
463-
464466
return $tokens;
465467
}
466468

0 commit comments

Comments
 (0)