Gren 0.4.5: Performance, Debugging, Web Crypto
Published: 2024-08-26Gren is a pure functional programmming language that aims to be easy to learn and to reason about, while remaining powerful and portable enough for real-world use.
New versions of the compiler and core packages are now available. You can expect better performance, improved debugging and more functionality.
Performance
The compiler generates more efficient JavaScript for function calls when it knows that the function in question isn’t curried. This reduces the call stack and makes it easier for the JavaScript engine to optimize the code.
This release also fixes a regression where math and comparison operators weren’t inlined properly for primitive types.
Together, these changes have resulted in a 2.8x improvement in the execution time of this particular program:
The implementation of Array.pushLast has also been improved, and now runs up to 3x faster.
A new module, Array.Builder, has been added to further improve performance of building large Array
s. It uses mutation under the hood, but it isn't observable outside of a debugger.
In summary, you should see noticeable improvements in performance with the latest compiler and core packages.
Improved debugging
The changes to the compiler also improves debugging by cleaning up the call stack. Function names now show up for uncurried function calls, and you’ll see a lot less application helpers (A2, A3, A4...).
Sourcemaps now also include the location of anonymous functions, which again improves the accuracy of the call stack while debugging.
A bug causing wrong line numbers for NodeJS applications have been fixed, as has a bug omitting the last line of the sourcemap.
Web Crypto
Gren programs now have access to the Web Crypto API. This lets you sign, verify, encrypt and decrypt Bytes
, as well as generate UUIDv4 strings and random Bytes
with a secure algorithm.
The Crypto module was implemented by Joey Bright, marking his first contribution to the core packages.
A note on the ChildProcess API
There’s a bug in the 0.4.4 compiler where the exit code is always zero, even when compilation fails.
This stems from missing functionality in the ChildProcess module. In order to fix this issue in a backwards compatible way, Justin Blake has added a new function called ChildProcess.spawnAndNotifyOnExit which works exactly like ChildProcess.spawn except that it notifies the application when the child process exits and which code it exited with.
This is just a temporary fix. We intend to rewrite the ChildProcess module in the next major release in order to clean up the API and add new functionality.
New functions
Besides the new Array.Builder and Crypto modules, existing modules have been updated with new functions:
- Array.insert
- Array.insertMany
- Array.remove
- Array.removeMany
- Array.setMany
- Array.splice
- Bitwise.countLeadingZeros
- Dict.updateWithDefault
- Math.maxFloat
- Math.maxSafeInteger
- Math.minFloat
- Math.minSafeInteger
- Maybe.checkValue
- Maybe.filter
- Maybe.hasValue
- Maybe.withDefaultLazy
- Result.allOk
- Result.checkValue
- Result.firstOk
- Result.hasValue
- Result.onError
- Result.withDefaultLazy
- Set.toggle