SuiteScript Performance: The Fixes We Make Most Often
Slow SuiteScript usually comes down to a few patterns. A user event script loads the same customer record for every line on an order. A scheduled script runs out of governance halfway through a batch. A client script runs a search on every field change, so the form lags while the user types.
None of these need clever tricks. They need less work per record, done in the right place.
Know what each call costs
NetSuite charges governance units for API calls and caps the units each script can use. A few numbers to keep in mind:
| Call | Transaction | Custom record | Other records |
|---|---|---|---|
record.load | 10 | 2 | 5 |
record.submitFields | 10 | 2 | 5 |
record.save | 20 | 4 | 10 |
search.lookupFields | 1 | 1 | 1 |
A user event script gets 1,000 units. A scheduled script gets 10,000. In a Map/Reduce script, each map call gets 1,000 and each reduce call gets 5,000. Check Oracle's governance documentation for the method you're using before you rely on a number.
You can log what's left at any point:
const remaining = runtime.getCurrentScript().getRemainingUsage();
log.debug({ title: 'Units left', details: remaining });
Log it at the start and end of each batch, not on every row.
Read fields without loading records
The single most common fix. If you need three fields from a sales order, don't load the whole record:
// 10 units, plus the time to load every field and sublist
const so = record.load({ type: record.Type.SALES_ORDER, id: orderId });
const status = so.getValue('status');
// 1 unit
const fields = search.lookupFields({
type: search.Type.SALES_ORDER,
id: orderId,
columns: ['status', 'entity'],
});
The same goes for writes. To update body fields, record.submitFields costs half of a load plus a save on a transaction, and it skips loading sublists you don't touch.
Search once, not once per line
Loading or looking up a record inside a loop is the pattern that eats governance fastest. Collect the IDs first, then run one search:
const itemIds = lines.map((line) => line.item);
const results = search.create({
type: search.Type.ITEM,
filters: [['internalid', 'anyof', itemIds]],
columns: ['itemid', 'custitem_lead_time'],
}).run().getRange({ start: 0, end: 1000 });
Ask for only the columns you need and put the filtering in the search, not in JavaScript after the results come back. For complex joins, SuiteQL through N/query is often simpler to write and faster to run than a saved search.
For more than 1,000 results, use search.runPaged(). Sort by a unique field like internal ID. Without a stable sort, rows can repeat or go missing between pages.
Put work in the right script type
User events run while someone waits for a record to save. Keep them short. Exit early when the event type doesn't need the logic:
function afterSubmit(context) {
if (context.type !== context.UserEventType.CREATE) return;
if (runtime.executionContext === runtime.ContextType.CSV_IMPORT) return;
// ...
}
If the work doesn't need to finish before the save completes, queue it. A Map/Reduce or scheduled script started with N/task keeps the user from waiting.
Client scripts run in the browser. A search in fieldChanged runs on every change. Load reference data once in pageInit, or call one Suitelet or RESTlet that returns everything the form needs.
Map/Reduce fits batch work that splits into independent pieces, like one key per customer or per order. NetSuite handles yielding and parallel processing for you. Make each piece safe to retry, and log failures with enough detail to rerun them. For small jobs, a plain scheduled script is easier to read and debug.
SuiteCommerce services run SuiteScript on shopper requests. Every unit and every millisecond there adds to page load time. Keep those services small, and move anything that can run ahead of time into a scheduled script that saves its results.
Cache what doesn't change often
N/cache saves the result of an expensive lookup, like a configuration record or a tax table, so the next run can skip it. Include every input that affects the answer in the cache key, set a sensible TTL, and write the code to handle a cache miss. Never cache customer-specific or permission-sensitive data under a shared key.
Measure before and after
For each slow script:
- Record the deployment, input size, time taken and units used.
- Find the repeated or expensive call in the execution log.
- Change one thing.
- Run the same input in a sandbox.
- Compare time and units, and check that the records it produced are still correct.
Oracle's Application Performance Management SuiteApp shows script timing across the account, which helps when you don't know which script is the slow one.
If a script is holding up your team, our SuiteScript development service covers performance reviews.