SCUA 0.42.0 spreads more of a program's work over your cores. When a
handler hands jobs to several partitions, idle cores now join in and run
them side by side, and large arrays of numbers move between partitions
without extra copies. The release also formats messages properly in
about 100 languages, with plural rules from CLDR and a new
msg.format for text that doesn't go through
render.
#A handler's fan-out now uses your cores
When a handler asks several partitions for work, the partitions now
run on the cores that would otherwise sit idle. The runtime learns what
each partition's turns cost, and wakes another core only when the work
outweighs the cost of waking it. Jobs of a few microseconds stay on one
thread, where they finish fastest, and work done inside a single
built-in call, such as a sort, is spread too.
partition Sorter
ask Sort(seed, n)
let xs: { i32 } = []
for i in 0:n do push(xs, (i * seed) % 1000003) end
sort(xs)
return xs[n // 2]
end
end
partition Job
on Run(n)
let ws = [Sorter(), Sorter(), Sorter(), Sorter()]
let medians = map_all(range(0, 4), fn(k) return ask ws[k].Sort(7919 + k, n) timeout 10s end)
print(`medians {medians}`)
end
end
tell Job().Run(200000)
$ scua sorts.scua
medians [499937, 499976, 499929, 499887]
The four sorts run at the same time. With two million numbers each,
this program takes 0.16 s on an Apple M4 Max, and 0.55 s with
--workers=1. In our tests, four partitions each sorting a
small array answered 3.6 times as fast on four threads as on one, and on
a two-core machine the second core helps too. The answer is the same
whatever the number of cores, and --workers=1 still runs
everything on one thread when you want a run you can repeat exactly. Set
SCUA_FANOUT_TRACE to see each decision the runtime
makes.
Handlers with long turns get the same benefit. When each core has a partition of its own and nothing else is waiting, a turn that reaches its pause point carries straight on, so partitions running at once on different cores no longer hold each other up.
The experimental threaded scheduler
(SCUA_SCHEDULER=threaded) spreads a fan-out across its
threads in the same way. On four threads, a handler asking four
partitions for 0.85 ms of work each gets its answers 3.9 times as fast
as on one.
Large arrays of numbers now move between partitions faster
On macOS and Linux, an array of numbers of 64 KB or more (8,192 ints,
or 16,384 f32s) now lives in a block of its own beside its
partition's heap, whether the partition built it, grew it with
push, sliced it or received it in a message. The sender
makes no spare copy before sending, and the receiver's memory
collections leave the array where it is. A handler that asks four
partitions for a job each, sending 100,000 numbers with every ask, takes
about 1.8 ms a round.
Nothing changes in what a program sees. The fastest pattern is still to send large data once and keep it in the worker, and the manual's Send large data once shows how.
#Plurals now follow CLDR in about 100 languages
@msg and the new msg.format choose between
zero, one, two, few,
many and other the way CLDR does for the
locale's language. Polish, Russian and Ukrainian get few
and many, Arabic uses all six, French puts 0 and 1 in
one, and Japanese, Chinese and Korean use
other for every count:
import msg
let coins = "{n, plural, one {# moneta} few {# monety} many {# monet} other {# monety}}"
for n in [1, 2, 5, 22, 25] do
match msg.format(coins, "pl", { n = n })
Ok(text) -> print(text)
Error(e) -> print(`{e.kind}: {e.message}`)
end
end
$ scua coins.scua
1 moneta
2 monety
5 monet
22 monety
25 monet
A language SCUA has no rules for gets CLDR's root rule, where every
count is other, so a message whose other case
reads well is right in any language.
#msg.format formats a message without render
msg.format(text, locale, args) takes an ICU
MessageFormat message, a locale and a table of arguments, and returns
Ok(text) or an Error that names what went
wrong. It follows the same rules as @msg, so you can format
a notification, a log line or an email subject without building a
render template around it.
Apostrophes now quote as they do in ICU, so '{' is a
literal brace and '{who}' prints {who}. An
apostrophe anywhere else is an ordinary apostrophe:
import msg
let line = "{who} found {n, plural, one {# coin} other {# coins}}. It's yours, '{who}'!"
print(msg.format(line, "en", { who = "Ann {the brave} #1", n = 3 }))
print(msg.format(line, "en", { who = "Bo", n = 2.5 }))
$ scua found.scua
Ok(Ann {the brave} #1 found 3 coins. It's yours, {who}!)
Error({kind = bad_argument, message = argument 'n' is a plural count and must be an int, not a float (2.5), argument = n})
#Player text now prints exactly as typed
Only the source is a template. A value that reaches
render through external, such as a player's
name, a chat line or a string from your database, now goes into the
output exactly as it is, wherever render uses it. If it
contains @{...} or @-keys, they print as text.
The same holds for @msg and msg.format
arguments: a name with {, # or '
in it prints as itself, as Ann's does above.
You no longer need to wrap player text in @raw to keep
it literal. The manual's Your
data is never a template also covers translations you don't
control.
#Smaller additions
math.f64_bits(x)andmath.f64_from_bits(n)give a float's exact 64-bit pattern and turn it back, NaN payloads and-0.0included, andmath.f32_bitsandmath.f32_from_bitsdo the same for 32 bits. With them, a decoder can write back a NaN it read as exactly the same bytes.bytes.put_u16lethroughput_u64be, andput_f32lethroughput_f64be, append a number to a{ u8 }in that width and byte order. In a hot loop they compile to a few instructions with no call: a 64-bit write takes about 4 ns on an 8-core x86 machine.- The top level of a program can now
aska partition and wait for the reply, and so can a test function underscua test. A script that wants an answer back no longer needs a partition of its own to ask from. type(v) == "float"and similar checks compile to a direct test of the value, with no call and no new string.
#Upgrading
@msgnow reports a wrong message or argument as an error. A missing argument printednil, a float plural count was cut down, and a string count read as 0. Each is now an error naming the argument, whichpcallcatches. Apluralorselectwith noothercase, a plural case that isn't a CLDR category or=N, and an unquoted{or}are errors too. To update, add anothercase where one is missing, quote a literal brace as'{', and pass every argument the message uses.- Plural rules for a language SCUA doesn't know are now CLDR's root
rule, where every count is
other. English rules were used before. Japanese, Chinese and Korean likewise now giveotherfor 1. @{...}inside data fromexternalis no longer resolved. If you relied on that, move the text into the source.- Use 0.42.1 if your data wraps text in
{ @raw = ... }. In 0.42.1 such a wrapper insideexternaldata stands for the text it wraps, as it did in 0.41.
#What's next
The next step lets partitions share data. A large array of numbers
that you freeze will be read in place by every partition
you send it to, with no copy made when it is sent. In our tests,
freezing the gradients a gradient-boosted tree library sends to its
workers made its training about 1.5 times as fast on four workers.
Frozen tables, records and strings follow.
The changelog lists everything else in 0.42.0 and 0.42.1.