SugarBean->cleanBean performance issue #4181

Open
opened 2026-02-20 16:14:37 -05:00 by deekerman · 2 comments
Owner

Originally created by @PedroErnst on GitHub (Dec 31, 2019).

The cleanBean function has a negative impact on performance.

Issue

Inside the bean save function cleanBean() is called to remove potentially malicious code. This function will call SugarCleaner::cleanHtml() on every text, html or varchar field on the bean.
The problem lies in that this function creates a new HtmlSanitizer object each time, and the constructor of HtmlSanitizer is badly bloated, executing a lot of things which would probably only need to run once per page load, not dozens of times per save operation.

On some test on my local cleanBean() was taking as much as 80% of the total time spent in the save() function.

Now this would hardly be noticeable in many of the regular CRM interactions, loading a page, a listview, detailview, saving a single record... etc, but there's a few functionalities where it really tanks performance: Importer and Mass Update.

The HtmlSanitizer constructor can probably be refactored to do less things, or converted into a singleton class to avoid being instantiated every time.

Expected Behavior

cleanBean() should be fast, it's essentially string processing.

Actual Behavior

cleanBean() takes an unreasonable amount of time to run.

Possible Fix

Refactor HtmlSanitizer to be singleton class, or make the constructor leaner.

Steps to Reproduce

  1. Profile SugarBean->save()

Your Environment

  • SuiteCRM Version used: SuiteAssured 2.0.5, SuiteCRM 7.10.22
  • Browser name and version (e.g. Chrome Version 51.0.2704.63 (64-bit)): Any
  • Environment name and version (e.g. MySQL, PHP 7): Any
  • Operating System and version (e.g Ubuntu 16.04): Any
Originally created by @PedroErnst on GitHub (Dec 31, 2019). <!--- Provide a general summary of the issue in the **Title** above --> <!--- Before you open an issue, please check if a similar issue already exists or has been closed before. ---> <!--- If you have discovered a security risk please report it by emailing security@suitecrm.com. This will be delivered to the product team who handle security issues. Please don't disclose security bugs publicly until they have been handled by the security team. ---> The `cleanBean` function has a negative impact on performance. #### Issue <!--- Provide a more detailed introduction to the issue itself, and why you consider it to be a bug --> <!--- Ensure that all code ``` is surrounded ``` by triple back quotes. This can also be done over multiple lines --> Inside the bean save function `cleanBean()` is called to remove potentially malicious code. This function will call `SugarCleaner::cleanHtml()` on every text, html or varchar field on the bean. The problem lies in that this function creates a new `HtmlSanitizer` object each time, and the constructor of `HtmlSanitizer` is badly bloated, executing a lot of things which would probably only need to run once per page load, not dozens of times per save operation. On some test on my local `cleanBean()` was taking as much as 80% of the total time spent in the `save()` function. Now this would hardly be noticeable in many of the regular CRM interactions, loading a page, a listview, detailview, saving a single record... etc, but there's a few functionalities where it really tanks performance: Importer and Mass Update. The `HtmlSanitizer` constructor can probably be refactored to do less things, or converted into a singleton class to avoid being instantiated every time. #### Expected Behavior <!--- Tell us what should happen --> `cleanBean()` should be **fast**, it's essentially string processing. #### Actual Behavior <!--- Tell us what happens instead --> <!--- Also please check relevant logs (suitecrm.log, php error.log etc.) --> `cleanBean()` takes an unreasonable amount of time to run. #### Possible Fix <!--- Not obligatory, but suggest a fix or reason for the bug --> Refactor `HtmlSanitizer` to be singleton class, or make the constructor leaner. #### Steps to Reproduce <!--- Provide a link to a live example, or an unambiguous set of steps to --> <!--- reproduce this bug include code to reproduce, if relevant --> 1. Profile `SugarBean->save()` #### Your Environment <!--- Include as many relevant details about the environment you experienced the bug in --> * SuiteCRM Version used: SuiteAssured 2.0.5, SuiteCRM 7.10.22 * Browser name and version (e.g. Chrome Version 51.0.2704.63 (64-bit)): Any * Environment name and version (e.g. MySQL, PHP 7): Any * Operating System and version (e.g Ubuntu 16.04): Any
Author
Owner

@Jason-Dang commented on GitHub (Dec 31, 2019):

This should probably be higher priority as performance should be critical IMO.

@Jason-Dang commented on GitHub (Dec 31, 2019): This should probably be higher priority as performance should be critical IMO.
Author
Owner

@Dillon-Brown commented on GitHub (Dec 31, 2019):

@Jason-Dang I'm thinking we probably need a label specifically for performance, I also didn't like giving this one just "Clean-Up" and "Low Priority".

In terms of the priority labels though, the performance would need to be bad enough that it's timing out / unusable to be worth marking higher. At the moment we have roughly 15 high priority blockers with limited or no-workaround that need to be tackled first before we can even start thinking about performance bugs imo.

@Dillon-Brown commented on GitHub (Dec 31, 2019): @Jason-Dang I'm thinking we probably need a label specifically for performance, I also didn't like giving this one just "Clean-Up" and "Low Priority". In terms of the priority labels though, the performance would need to be bad enough that it's timing out / unusable to be worth marking higher. At the moment we have roughly [15](https://github.com/salesagility/SuiteCRM/issues?q=is%3Aopen+is%3Aissue+label%3A%22High+Priority%22) high priority blockers with limited or no-workaround that need to be tackled first before we can even start thinking about performance bugs imo.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/SuiteCRM-SuiteCRM#4181
No description provided.