Lukáš Astaloš UK-based Certified SuiteCloud Developer I & II from Slovakia. Highly motivated and focused on the delivery of powerful and flexible technical solutions when standard NetSuite functionality is not enough. Passionate about space and historical reenactment.

Comparison of SuiteScript Approaches to Find a Sublist Line with a Specific Value

4 min read

Performance awareness is an essential skill of a NetSuite Developer, one that can draw a line between a good and bad script. Achieving a business requirement is only one part of the job but without proper performance consideration, it’s not enough. In this article, I compare two common approaches for finding the sublist line that contains a particular value.


Introduction

As developers, we often need to find a sublist line with a specific value. There are two simple approaches frequently used to do this: Record.findSublistLineWithValue native SuiteScript method or looping through all the sublist lines and comparing the values. While I was reviewing the code of other developers in the past, I noticed several times that they didn’t know about the existence of the Record.findSublistLineWithValue method and used the other approach instead. So I was wondering, is the SuiteScript method just a fancy wrapper that does the same, or is there an actual performance difference, and if so, how large is it?

The first thing that would pop into our heads when we’re talking about performance in regards to NetSuite development is the SuiteScript Governance and limits. Luckily, none of these approaches consumes any usage units. So, I decided to conduct an experiment and I am pleased to share my findings with you.

Test Setup

The test record was a Sales Order (SO) with 500 item lines in a test drive (TSTDRV) account. Except for the testing script, there was no other custom script or workflow deployed on the SO record. The goal was to find one item line with a specific value, which was actually only present on the last, i.e., 500th line.

I conducted the experiment for client-side using a client script running the line search in the pageInit entry point. It was executed in two Chrome incognito tabs with the SO with 500 lines open in edit mode and with no active Chrome extensions. The client script reloaded the page after it found the line, doing this 100 times for each tab. 

I subsequently repeated the experiment using a scheduled script to see how the approaches perform server-side and to eliminate browser-specific effects. The script re-scheduled itself after each run.

The simple test script is shown below:

Test Script Used For The Experiment

Results

Several questions emerged during the experiment that led me to try a few variations of the code. Here is what I tried to get answers for:

  1. What is faster? Looping or Record.findSublistLineWithValue?
  2. Is there a speed difference between SuiteScript 2.0 and 2.1?
  3. Is the performance dependent on the field where I’m looking for the value? I tried to look in lineuniquekey, item, and quantity.
  4. Is there a speed difference between standard (deferred) and dynamic mode (only applicable for server-side in the experiment)?

Below are summarized results I got from 100 attempts for each variation (200 for client-side as I tested on 2 browser tabs). The table header says what field we searched for the value in, what kind of approach (‘loop’ or ‘find’), and variation (SuiteScript version and static/dynamic mode) was used. The reported execution times are in seconds. The best average result is highlighted in green color.

Client Side

lineuniquekeyloop|2.0loop|2.1find|2.0find|2.1
Avg0.0095650.009790.0030150.003435
Avg performance-3.17x-3.25x1x-1.14x
Median0.0090.0090.0020.002
Min0.0080.0080.0020.002
Max0.0160.0270.010.008
itemloop|2.0loop|2.1find|2.0find|2.1
Avg0.00980.009570.0045450.002125
Avg performance-4.61x-4.5x-2.14x1x
Median0.010.0090.0030.002
Min0.0090.0090.0020.002
Max0.0160.0160.1150.004
quantityloop|2.0loop|2.1find|2.0find|2.1
Avg0.0085150.008690.004270.002145
Avg performance-3.97x-4.05x-1.99x1x
Median0.0080.0080.0030.002
Min0.0070.0070.0020.002
Max0.0160.0160.0140.004

The answer to the first question, which approach is faster is pretty clear, it’s the SuiteScript Record.findSublistLineWithValue method. What is faster, SuiteScript 2.0 or 2.1? It seems there is no real difference for looping approach but findSublistLineWithValue performs better in SuiteScript 2.1 except for the lineuniquekey search where SuiteScript 2.0 marginally outperforms 2.1. Perhaps the takeaway here is to use SuiteScript 2.1 whenever possible as it gives better performance in general.

Is there a difference based on the field? Lineuniquekey seems to be slowest but the difference does not appear to be significant.

On client-side, NetSuite's Record.findSublistLineWithValue could be up to 4.5 times faster than simply looping through all sublist lines in search of the target value. Click To Tweet

The client script did the searching on the actual record opened in the browser (scriptContext.currentRecord). So, I also decided to try searching on loaded record (record.load) instead, this time, only for lineuniquekey. The results were quite surprising. From the table below we can see that findSublistLineWithValue performs significantly faster on loaded record!

lineuniquekeyloop|2.0|loadedloop|2.1|loadedfind|2.0|loadedfind|2.1|loaded
Avg0.56030.5127750.002310.00149
Avg performance-376.04x-344.14x-1.55x1x
Median0.47350.48450.0020.001
Min0.4180.3760.0010.001
Max1.1441.0190.0070.002

Server Side

S = record loaded in standard mode, D = record loaded in dynamic mode

line unique keyloop|2.0|Sloop|2.0|Dloop|2.1|Sloop|2.1|Dfind|2.0|Sfind|2.0|Dfind|2.1|Sfind|2.1|D
Avg0.070570.077770.075320.083470.019160.018630.017660.02054
Avg performance-4.0x-4.4x-4.27x-4.73x-1.08x-1.05x1x-1.16x
Median0.0660.0720.0730.080.0170.0170.0170.018
Min0.0490.0530.0520.0630.0130.0140.0130.014
Max0.1820.1550.1420.1610.1350.0360.0370.079
itemloop|2.0|Sloop|2.0|Dloop|2.1|Sloop|2.1|Dfind|2.0|Sfind|2.0|Dfind|2.1|Sfind|2.1|D
Avg0.068360.078590.080930.081170.017660.018080.017390.0221
Avg Performance-3.93x-4.52x-4.65x-4.67x-1.02x-1.04x1x-1.27x
Median0.0650.0730.07150.0760.0170.0170.0170.018
Min0.0480.0560.050.0560.0120.0130.0130.013
Max0.1140.1430.5390.2320.0280.040.0330.219
quantityloop|2.0|Sloop|2.0|Dloop|2.1|Sloop|2.1|Dfind|2.0|Sfind|2.0|Dfind|2.1|Sfind|2.1|D
Avg0.077650.092630.086470.100140.017940.018020.01790.01789
Avg Performance-4.34x-5.18x-4.83x-5.60x-1.0028x-1.0073x-1.0006x1x
Median0.0730.0840.0850.09450.0170.0170.0170.017
Min0.0530.0670.0620.0730.0130.0130.0130.015
Max0.1370.4630.1710.2080.0290.0280.0340.034

The winner is again without any doubts the findSublistLineWithValue method. SuiteScript 2.0 seems to be a bit faster for looping approach but also in this case we cannot answer the question unambiguously. Is there a difference between the fields – no, not really.

On server-side, NetSuite's Record.findSublistLineWithValue also significantly outperforms the looping approach by more than 5 times in some cases. Click To Tweet

One extra question that I did not test in client side was whether there is any significant speed difference between standard and dynamic record mode. As can be seen from the above results, dynamic mode appears to be slightly slower in most of the cases, especially for looping approach. This is consistent with expectations as dynamic mode mimics the UI and thus, typically introduces some overhead.

One last quick test I did was to compare the performance of two approaches when searching for multiple values. The test was performed using SuiteScript 2.1 and record loaded in standard mode, searching for lineuniquekey present on 200th, 400th and 500th lines.

lineuniquekeyloop|2.1|loaded|multiplefind|2.1|loaded|multiple
Avg0.079830.04351
Avg Performance-1.831x
Median0.0710.039
Min0.0490.03
Max0.170.26

Conclusion

Based on the result of this experiment, I believe it is safe to state that Record.findSublistLineWithValue is faster than looping and should be used if we need to find a unique (or the first instance of a) value in a sublist. SuiteScript version, record mode, and the actual field being searched for seem to be insignificant factors in determining the performance. There are other questions that one could further explore, for example:

  1. Do the results change when run using a sublist of a non-transaction record type e.g. a custom record sublist?
  2. Does it matter whether the field being searched for is a native field or a custom field?

The interested reader is invited to investigate further and share their findings.


NetSuite Insights is on a mission to raise the standards around NetSuite practices, one insight at a time. If that resonates with you, check out how you can become an author/collaborator here.

Also, subscribe to our no-nonsense email list to get these insights delivered to your inbox as soon as they’re published. Sometimes, ignorance is a choice. Choose wisely!


Lukáš Astaloš UK-based Certified SuiteCloud Developer I & II from Slovakia. Highly motivated and focused on the delivery of powerful and flexible technical solutions when standard NetSuite functionality is not enough. Passionate about space and historical reenactment.

2 Replies to “Comparison of SuiteScript Approaches to Find a Sublist Line with a Specific Value”

  1. Great article! We would love to see more like these! It’s really helpful to quantify the performance of different aspects in the SuiteScript API.

    1. We agree, Ben, that we need more of these kinds of performance experiments in the NetSuite space. Some of the reluctance might be the result of NetSuite’s ToS which generally frown upon benchmarking.

Leave a Reply

Your email address will not be published. Required fields are marked *

×