Optimizing SuiteScript Performance
There are certain changes you can make to your scripts to ensure the execute with performance in mind. This may be particularly true for custom scripts. You can see if there are custom scripts in your account at Customization > Scripting > Scripts. The following guidelines are suggested to optimize script performance:
General Scripting Guidelines
-
Consider using SuiteScript 2.1 language constructs and converting your SuiteScript 2.0 scripts to SuiteScript 2.1. Some SuiteScript 2.1 language constructs can be used to improve script performance and script performance may be increased by using the SuiteScript 2.1 Graal runtime engine. For more information about SuiteScript 2.1, see SuiteScript 2.1.
-
Save retrieved values on a variable and use again on succeeding calls.
-
Execute a block of code only if it satisfies a condition.
-
Remove redundant operations or actions and lines of code which are no longer used within the script execution.
-
Remove duplicate logic on a script that is already performed by other events.
-
Combine similar scripts/functions whenever possible.
-
Inactivate scripts/deployments that are no longer needed.
-
Use asynchronous processing for user events.
-
Use built-in permissions (by leveraging Run as Role) instead of scripting permissions.
-
As a general rule, design your user event scripts to execute in under 5 seconds, your Suitelets and Portlets to execute in under 10 seconds, and your scheduled scripts in under 5 minutes. This gives you a large enough margin of error to handle the outlier use cases (where the volume of work is unusually large, or the overall system is slow due to high load).
-
To minimize execution logging after your script is tested and released, set your script log level to ERROR or EMERGENCY. See Setting Script Execution Log Levels.
-
Deploy scripts to run as administrator only if necessary to minimize security risk and to eliminate performance overhead. See Executing Scripts Using a Specific Role.
-
Use execution context filtering to specify how and when a client script or user event script is executed. Execution contexts provide information about how a script is triggered to execute. For example, a script can be triggered in response to an action in the NetSuite application, or an action occurring in another context, such as a web services integration. You can use execution context filtering to ensure that your scripts are triggered only when necessary. For more information, see Execution Contexts.
Accessing Records in Scripts
-
If applicable, change the trigger of a script to avoid reloading a record.
-
Avoid saving records multiple times in an After Record Submit event.
-
Avoid loading and submitting a record on a Before Record Submit trigger.
-
Minimize API calls that perform load, search, or save record operations.
-
Use inline editable child custom records whenever your use case calls for batch processing of multiple related/child records during user events on the parent record. (See Custom Child Record Sublists in the NetSuite Help Center.)
Scripting Searches
-
Optimize search filters and columns. Make your search results faster by:
-
Filtering inactive records.
-
Entering shorter date range criteria.
-
Using faster operators such as starts with/between/within instead of contains/formulas.
-
Removing unnecessary columns.
-
-
Remove search results columns that are not used by a script. Place any lines that add columns to search results in a comment. Then the returned values are not used by the succeeding script logic.
-
Combine searches of the same record type by using merged filters. Wherever possible, combine searches for the same record into one main search with merged filters. This improves performance by minimizing search instances.