This Month with Nim: April and May 2022
01 June 2022 The Nim Community
After maintaining 3 sets of REST API bindings in Nim I’ve amassed some useful boilerplate which the community will benefit from.
- Out of the box support for native C / C++ and JS backend.
- Built in jsony hooks for:
- snake_case APIs,
- Option types,
fastsyncpragma from asyncutils to enable sync / async with reduced code duplication.
The Small String Optimized (SSO) string data-type attempts to reduce the number of heap allocations that happen at runtime.
When a string is less than 23 bytes on 64bit it can be stored directly in the object. Avoiding a dynamic allocation. There exist two modes for each String. A short string and a long string mode in which the dynamic memory is managed using Nim’s destructors.
The implementation is based on clang’s std::string class. This technique might improve runtime performance and reduce fragmented memory where this is most needed, i.e. on embedded systems.
Copy-On-Write string data-type provides an implementation of mutable strings so that creating and copying them is free performance wise.
The object’s internal memory is reference counted and shared among it’s instances. Thus it only make a copy for a specific instance, when it’s data is modified. It is based on nim-lang/RFCs#221. It should improve performance when strings are frequently copied. Passing a string to a thread triggers a deep copy, so it is compatible with multi-threading.
Authors: Jesper Svedberg
Tpix is a simple terminal image viewer written in Nim.
It is compatible with terminal emulators that supports the kitty graphics protocol and uses the Pixie graphics library to read and render images. Tpix is available as a statically linked single binary that is easy to deploy on remote systems where the user does not have root privileges.
Tpix can view the following image formats: PNG, JPG, GIF (animated GIFs not supported), BMP, QOI, PPM and SVG (currently only limited support). Tpix has so far been compiled on x86_64 and arm64 Linux, x86_64 MacOSX, and it has been tested with Kitty and Wezterm.
Want to see your project here next month?
Follow this to add your project to the next month’s blog post.