Email sending hangs on very large emails

Description

Hi Tibor!

When we try to send emails with very large body with lots of images, it hangs for a very long time causing overall system slowness.

Out performance monitoring tool showed that the problem occurs when JETI tries to replace image links with cids in SmartEmail.referImageLinkToPart:
body = body.replaceAll("(?i)(?s)(<img
s.?src.?=.?)(" + link + ")(.?>)", "$1" + "cid:" + cid + "$3");

It had been executing for 2 hours when we had killed the process as it slowed down our system.

Could you please try to optimize the performance of this regex?
I attached a screenshot from our monitoring tool.

Regards,
Máté

Environment

None

Preliminary Test Cases

None

Activity

Show:
Tibor Hegyi
June 18, 2016, 1:05 PM

Thank you for your detailed feedback, we'll try to optimize this procedure. Can you let me know how large your email was?
Tibor

Mate Smajda
June 21, 2016, 12:54 PM

I made some research, it took our dev system 120 sec to send an email which is ~900k characters long with 15-20 image links. When I reduced the image links to ~10, it dropped to 40sec, so I think the matching is quite fast, but replacing the link is the expensive operation. The issue which took 2+ hours is much larger, it's easily reproducible by adding more characters/links.

Tibor Hegyi
August 5, 2016, 5:41 AM

released in 7.0.19

Geza Nagy
August 5, 2016, 11:43 AM

Thanks Tibor!

Regads,
Geza

Tibor Hegyi
August 5, 2016, 12:33 PM

Hi Géza, was your research done with the old version or the new one we released today?

The former version implemented link replacement using String.replaceAll(). It replaces regex with regex.
The new version implements the same logic with StringBuilder.indexOf() and StringBuilder.replace().

regards,
Tibor

Done

Assignee

Tibor Hegyi

Reporter

Mate Smajda

Labels

None

Access to limited visibility issues

None

Product platform

None

Module Dependency

None

Ready for Development

None

Target version

None

Fix versions

Affects versions

Priority

Major
Configure