Compiler ยท Mar 12, 2020

Announcing BuckleScript 7.2

This release will give us some small quality of life improvements for tool builders, better performance, and a new let %private modifier for hiding module functionality.
Hongbo Zhang
Compiler Team

About the Release

Today we are proud to release bs-platform 7.2!

For those unfamiliar with bs-platform, it is the platform for compiling ReasonML and OCaml to fast and readable JavaScript.

You can try it with npm i bs-platform!

Features

In memory loading stdlib

Since this release, the binary artifacts generated by the stdlib are loaded from memory instead of an external file systems, which means much faster compilation and installation.

Previously we recommended installing bs-platform globally to save on installation time.

However, with this release the installation is so fast that we recommend installing it locally instead - per project - instead, as there's no additional cost, and it provides better isolation.

You can use it with a nice tool called npx, for example, npx bsb.

The installation is also compatible with --ignore-scripts for major platforms (see Richard Feldman's talk on the security implications), and is more stable with yarn

More technical details can be found in this post.

let %private

In OCaml's module system, everything is public by default, the only way to hide some values is by providing a separate signature to list public fields and their types:

RE
module A : { let b : int} = { let a = 3 ; let b = 4 ; }

let %private gives you an option to mark private fields directly

RE
module A = { let%private a = 3; let b = 4; }

let%private also applies to file level modules, so in some cases, user does not need to provide a separate interface file just to hide some particular values.

Note interface files are still recommended as a general best practice since they give you better separate compilation units and also they're better for documentation. Still, let%private is useful in the following scenarios:

  • Code generators. Some code generators want to hide some values but it is sometimes very hard or time consuming for code generators to synthesize the types for public fields.

  • Quick prototyping. During prototyping, we still want to hide some values, but the interface file is not stable yet, let%private provide you such convenience.

Int64 performance optimization

We received feedback from some users that various Int64 operations became bottlenecks in their code performance, in particular Int64.to_string.

We responded to this, and after some hard work - but without changing the underlying representation - our Int64.to_string is even faster than bigint for common inputs.

A micro-benchmark for comparison:

running on 7.1 Int64.to_string: 367.788ms # super positive number Int64.to_string: 140.451ms # median number Int64.to_string: 375.471ms # super negative number bigint Int64.to_string: 25.151ms Int64.to_string: 12.278ms Int64.to_string: 21.011ms latest Int64.to_string: 43.228ms Int64.to_string: 5.764ms Int64.to_string: 43.270ms

We also apply such optimizations to other Int64 operations.

Note that Int64 is implemented in OCaml itself without any raw JavaScript. This is case compelling hints that our optimizing compiler not only provides expressivity and type-safe guarantees, but also empowers users to write maintainable, efficient code.

File level compilation flags

In this release, we also provide a handy flag to allow users to override some configurations at the file level.

RE
[@bs.config {flags: [|"-w", "a", "-bs-no-bin-annot"|]}]; // toplevel attributes

A full list of changes is available here: https://github.com/BuckleScript/bucklescript/blob/master/Changes.md#72

This article was originally released on https://bucklescript.github.io/blog/2020/03/12/release-7-2
Want to read more?
Back to Overview