Halved latency: Web framework IHP 1.5.0 with new database layer

The web framework IHP 1.5.0 brings a new database layer, significant performance gains, and an improved modular architecture.

listen Print view
Illustration of web development with computer, databases, clouds, and tools.

(Image: heise medien)

4 min. read
Contents

The web framework IHP is now available in version 1.5.0. This is the largest release of the open-source project to date, with 1,051 commits. The developers have rewritten the entire database layer, improved performance in many areas, and modularized the architecture.

IHP (Integrated Haskell Platform) is a web framework that includes many functions typical for web applications out-of-the-box. It combines the functional programming language Haskell with the package manager Nix. Nix ensures reproducible development environments. The framework is aimed at developers and teams who want to build web applications with high type safety and as few runtime errors as possible. IHP provides all the necessary tools for this, from prototyping to production.

The biggest change in version 1.5.0 concerns database access. IHP is switching from the older driver postgresql-simple to hasql. This more current driver uses PostgreSQL's binary protocol and works with prepared statements. In production environments, this reduces latency for database queries by up to 50 percent. The existing query builder API remains unchanged; existing code will continue to work without modifications. Only those who have previously accessed postgresql-simple directly need to migrate.

Furthermore, the IHP developers have also accelerated other parts of the framework. According to the release notes, the integrated development server, which is based on GHCi, the interactive environment of the Haskell compiler, now only uses 500 to 800 MBytes of RAM instead of the previous 4 GBytes. The session middleware is also said to work three times faster for routes that do not access the session. URL generation is said to be five times faster, and the rendering pipeline twice as fast as in the previous version after the update.

The new package ihp-typed-sql introduces a so-called quasiquoter – a Haskell mechanism that allows SQL syntax directly in the code. The special feature: The compiler connects to the development database during the compilation process and checks whether tables, columns, and data types are correct. It also recognizes which columns can become null values through LEFT JOIN. Incorrect SQL queries are thus detected during the build, not just at runtime.

With the new function fetchPipelined, developers can send multiple independent database queries to PostgreSQL in a single network roundtrip. Instead of sending each query individually and waiting for the response, IHP sends all queries directly one after another. The database processes them and returns the results bundled. This noticeably reduces network latency.

With this version, IHP is less monolithic. The developers have published over 15 modules – including ihp-mail, ihp-datasync, and ihp-schema-compiler – as standalone packages on Hackage, the central package repository for Haskell (comparable to npm for JavaScript or PyPI for Python). Other Haskell projects can thus use these libraries without integrating the entire framework. Existing IHP projects are not affected; the modules are still re-exported from the main package.

Videos by heise

In addition, version 1.5.0 brings, among other things, custom routes for individual URLs alongside automatic routing, support for composite primary keys, and an integration test mode with an automatically generated temporary PostgreSQL database. GHC 9.10 now serves as the default compiler; IHP also supports GHC 9.12 experimentally.

Since the database layer change and modularization involve some breaking changes, the development team provides an upgrade guide with step-by-step instructions. All information can be found in the release notes on GitHub.

(fo)

Don't miss any news – follow us on Facebook, LinkedIn or Mastodon.

This article was originally published in German. It was translated with technical assistance and editorially reviewed before publication.