2026-07-06

Object Pascal Is Still a Serious Contender for High-Performance REST Servers

In this article, we will deep-dive into the architecture that lets our Open Source mORMot 2 library compete with (and sometimes outperform) nginx, Kestrel, and raw C++ implementations.

The library offers several HTTP servers.
The mormot.net.server unit contains the historical mORMot 1 web servers - mainly THttpServer (thread-pool for HTTP/1.0 short requests + one thread per kept-alive HTTP/1.1 connection), and THttpApiServer (using the efficient http.sys kernel API on Windows).
But since mORMot 2, our mormot.net.async unit is our genuine cross-platform, modern async implementation.

As Linus Said: It's All About Data Structures

After years of work on the asynchronous HTTP server in mORMot 2, I’m convinced that language choice is less decisive than people think — it’s the engineering decisions that matter.

This server regularly ranks near the top of TechEmpower (including #1 in cached ORM results in several rounds).

Here’s how we built it.

OS-Specific Networking: No One-Size-Fits-All

We deliberately use different strategies per platform:

  • Linux: Straight epoll with edge-triggered notifications. Clean, mature, and extremely efficient for our event-driven model. I evaluated io_uring but concluded that for typical REST/JSON traffic over regular Ethernet, the added complexity wasn’t worth the marginal gains.
  • Windows: IOCP with an asymmetric pattern. We receives normally via IOCP registration, but for small dynamic responses (the dominant case), we call plain send() directly on the socket instead of registering the write operation. Only large file transfers go through full overlapped I/O registration.
  • BSD flavors (like MacOS or OpenBSD/FreeBSD): Regular poll API which gives good enough performance.

On those platforms, switching to an asynchronous pattern allowed serving thousands of concurrent connections from a few threads. This is the main benefit against our previous THttpServer class, which still shines behind a nginx proxy, for instance.

On Windows, the difference between http.sys and IOCP is significant. Microsoft has long promoted http.sys as the ultimate high-performance solution on Windows. It shines for static files thanks to kernel-mode caching and zero user-mode transitions. However, for dynamic content generated in userland (JSON, templated HTML, etc.), our raw IOCP implementation is faster in practice — my tests showed roughly 50% faster with IOCP than with http.sys for serving 4KB of JSON. Sometimes the general-purpose kernel abstraction adds more overhead than it saves.

For the TechEmpower benchmarks, we scaled by running multiple HTTP server instances inside the same process, spreading load across available cores, sharing as many memory as possible. Simple, but very effective. On modern hardware and OS, switching to a full asynchronous model in the code is sometimes not mandatory, and adds some overhead due to compiler magic - like an hidden state machine for no benefit.

Memory Discipline: The Real Secret Weapon

Modern performance is often limited by allocator pressure and cache misses more than raw CPU cycles.

In mormot.net.async we go to great lengths to avoid allocations on the hot path:

  • A typical static GET request requires only one allocation — the URI string. All other buffers are static or reused.
  • Response construction, header generation, and JSON serialization reuse pre-allocated structures aggressively - which is where the mormot.core.json library kernel shines.

We also rely on a highly tuned Radix Tree (compressed trie) for URI routing and parsing. It provides excellent lookup performance with low memory overhead and predictable cache behavior.

This allocation-avoidant design is one of the main reasons Pascal stays competitive: the language gives us excellent control over memory layout and lifetime without the usual safety/GC tax of higher-level languages.

Production Features Done Right

Performance without operability is useless. So we integrated several key capabilities with minimal impact on the critical path:

  • IP threat mitigation via THttpAcceptBan — easy to load Spamhaus or custom CIDR blacklists
  • Authentication — Basic, Digest, JWT and full enterprise-grade Kerberos via SSPI/GSSAPI
  • Efficient logging with THttpLogger (Apache/Nginx compatible format, but designed for low overhead at high throughput)
  • Global analytics & monitoring through THttpAnalyzer for consolidated response statistics e.g. per month/day/hour
  • WebSockets ready via the mormot.net.ws.async unit.

And since mORMot 2 is used in several business-critical projects, we have immediate feedback from end users, in a vast variety of production environments.

Real-World Complexity: Progressive Caching

One unique feature set is our proxy/peer cache support.
When serving partially filled content (data still arriving from another backend connection), we use registered writes + a lightweight background thread to push new chunks as they become available. Once the resource is complete, we switch to the fast direct-send path.

This design prioritizes stable bandwidth sharing across concurrent clients rather than single-client peak throughput — exactly what you need in real cache/proxy scenarios.

Linux vs Windows: Facing the Facts

On identical hardware, the Linux version delivers more than twice more throughput for dynamic JSON workloads than the Windows IOCP version.
This is largely due to differences in kernel network stacks, scheduler behavior, and ecosystem tuning. Windows IOCP still performs very well (and beats nginx on the same OS), but the gap exists.

We accept this reality. In practice, Windows is more than fast enough for most deployments — especially when you value its authentication ecosystem or existing IT infrastructures. But Linux is the way to go if you want to leverage hardware and software to the next level of stability and production state.

Why Pascal Is Still in the Race in 2026

Modern Object Pascal (especially Free Pascal + mORMot 2) gives us a rare combination:

  • Low-level control comparable to C/C++ (manual memory management, static buffers, direct OS API access)
  • High-level productivity (clean syntax, powerful RTTI, excellent mORMot 2 standard library)
  • Predictable performance without GC pauses or hidden costs

The result is a software solution that is fast where it counts, maintainable, and remarkably stable in production.
Your high-level service code could still be written with safe and clean high-level object pascal types (string, interface, generics, dynamic arrays, RTTI...) and let all the low-level plumbing be done at mORMot 2 level. A technical solution to consider for sure.

Closing Thoughts

TechEmpower is excellent for motivation and cross-framework comparison, but real success is measured in long-running production servers handling sustained traffic with monitoring, security, and reliability.
It is worth noting that the TFB challenge has been recently shut down, and their github repository archived since March 2026. They did not give any reason, but it may be because the main sponsor, Microsoft which gave the HW, was not able to reach the top level with C# as it is possible with our good old pascal code - only guessing, of course. It was a third-party benchmark, well known and with a lot of contenders, but only a micro-benchmark for sure.

Our mormot.net.async was built with production-ready-code in mind. It’s not trying to win every micro-benchmark — it’s trying to be an excellent, pragmatic choice for real REST services.

The code is open source. If you’re curious about high-performance networking, low-allocation design, or cross-platform systems programming in Pascal, I invite you to take a look.
As always, questions and contributions are always welcome on our forum.

2026-06-02

TPipeStream: A High-Performance In-Memory Pipe for Delphi and FPC

The latest version of mORMot 2 introduces TPipeStream, a new TStream descendant designed to efficiently transmit data between two threads.

At first glance, the class looks deceptively simple: one thread writes data using Write(), another thread reads it using Read().
Behind this familiar interface lies a fast, lock-protected ring buffer with blocking semantics, making it suitable for streaming large amounts of data between independent producer and consumer threads.

Continue reading

2026-05-19

Delphi Linux & macOS Support for mORMot 2

We are pleased to share that mORMot 2 now offers initial compatibility with Delphi's Linux and macOS x86_64 compilers for console/server applications.
This effort originated from GitHub issue #442.

Thanks to community testing and contributions, core units now compile and run on these platforms.

Continue reading

2026-03-03

Rencontre entre Pascaliens à Nantes

Si vous êtes dans l'Ouest de la France, vous êtes les bienvenus pour une escale Delphi/Lazarus le jeudi 9 avril fin d'après midi à Nantes!

J'y serais avec toute l'équipe dev de Tranquil IT pour partager des idées, et certainement quelques petites choses plus solides (ou liquides) ! :)

Continue reading

2026-01-14

mORMot 2 Generics Scalability

In the world of Delphi development, generics have become a cornerstone for writing flexible, type-safe code. However, as projects grow in complexity—with hundreds or even thousands of generic specializations—the scalability of these implementations can become a critical bottleneck.
If you're dealing with large-scale applications, these insights could save you hours of build time and frustration.

Continue reading

2026-01-12

New mORMot 2.4 Release

After more than one year since our latest release, it is time for a new release!

Continue reading

2025-11-09

Sneak Peek mORMot 2.4: SCRAM-MCF REST Authentication

With the upcoming 2.4 release of our framework, we completed its REST authentication process, to follow state of the art principles like MCF strong hashing and SCRAM mutual authentication, with secure password storage on the server side.

This blog article will detail the background information needed to identify what is really going on.

Continue reading

2025-10-29

EKON 29 Slides

The EKON 29 Konference in Dusseldorf just ended.

Nice year, with a lot of AI talks.
To keep the pressure low, I did not talk about AI, but gave 3 sessions and 1 workshop about mORMot. Here are the slides I used.

Continue reading

- page 1 of 52