A bundling context is an isolated layer in the bundling cycle that is allocated a set task that generalizes the concept of bundling in Packem.
Previously, we’ve mentioned that Packem uses OS-specific precompiled binaries to handle bigger tasks in the bundling cycle such as module graph generation. However, to integrate with tools like Babel and such, a custom runtime in Rust would be necessary. However this means much more than it sounds. Creating an entire runtime in Rust that strictly follows ECMAScript’s standards is exceedingly difficult, yet not impossible.
- Logical Context (LC) - This section entails most of the logic Packem uses to instantiate and rehydrate the module graph. It is written strictly in Rust and in most cases, performance-critical parts are abstracted into this layer. However, exceptions to this rule do remain especially in the domains of Packem not having support for them in the moment.
Switching between the LC and RC can cause a performance delay since the FFI bindings yield the effect with an extra overhead causing build times to be a bit higher. This is why:
- Necessary decisions are made before hand in the RC to avoid unnecessary calls between the two contexts.
- A minimal functional interface is exposed to the RC.
- Non-performance-critical parts of Packem are regressed into the RC.
Mutation of the module graph can occur anywhere between the LC and the RC.