ID:2816256
 
BYOND Version:514
Operating System:Windows 10 Pro
Web Browser:
Applies to:Dream Seeker
Status: Open

Issue hasn't been assigned a status value.
Descriptive Problem Summary:

Numbered Steps to Reproduce Problem:

Code Snippet (if applicable) to Reproduce Problem:
/proc/main()
var/list/L = list()
// === Change 1000 to however big you want your list ===
for (var/i in 1 to 1000)
L += i

sleep(1)

var/count = 0
var/start = world.tick_usage
while (world.tick_usage - start < 100)
count += 1

// === Uncomment whichever one you want to test ===

// json_encode(L)
// L.Join("-")

world.log << count


Expected Results:
Join() would be as fast, or faster, than json_encode, as it should have to do significantly less work.

Actual Results:
In 0.1s, both functions perform this number of calls:

Empty list (Join is 66% faster):
- json_encode(L): 134,474
- L.Join("-"): 223,724

One entry (Join is 15% slower):
- json_encode(L): 114,873
- L.Join("-"): 99,524

Five entries (Join is 18% slower):
- json_encode(L): 57,195
- L.Join("-"): 48,386

1,000 entries (Join is 72% slower):
- json_encode(L): 624
- L.Join("-"): 361
(If you were curious, jointext is slightly faster than list.Join, but still much slower than json_encode)
jointext() and list.Join() are the same under the hood, but the built-in proc is always slightly faster just because it doesn't have to go through some of the same hoops to begin the proc.

I took a look, and internally the join is relying on FTextValue() (this is the workhorse that also gets used in embedded string arguments like "Price: $[price]") to convert a number to text, although that should be rather fast. The only appreciable difference is that the format specifier used for the number printing is different in FTextValue() than it is in the StringEditor class routine used by json_encode().

I personally think I need to change the way FTextValue() handles numbers to be consistent with what StringEditor uses anyway, so if I make that change it should, I think, fix the problem entirely.
Looks like list2params is also slightly slower than json_encode :P