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.
Thank you for your detailed feedback, we'll try to optimize this procedure. Can you let me know how large your email was?
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.
released in 7.0.19
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().