Urgent.News

What's breaking now, across thousands of outlets.

Tech

JIT Compiling Code in 5μs

In the realm of programming, fast Just-In-Time (JIT) compilation has often been considered a complex endeavor, requiring expertise in assembly language. However, recent advancements in artificial intelligence have made it much simpler to create JIT compilers that compile code at runtime with remarkable speed. This breakthrough is particularly impactful for databases, which previously relied on slower compilation methods like LLVM or C/C++ code generation.

One noteworthy example of this advancement is the pgrust project, where the author initially doubted the feasibility of implementing a JIT compiler. Yet, with the help of AI, the process turned out to be far more straightforward than anticipated, contributing to the project's overall performance. The pgrust JIT compiler can compile code in just 5 microseconds, allowing it to JIT compile every SQL query, rather than just a fraction of them.

JIT compilation is a technique that generates executable code at runtime, often resulting in significant performance improvements, typically ranging from 2 to 5 times faster, and sometimes even more. This technique is especially valuable when programming language interpreters encounter runtime information that significantly alters program behavior. JIT compilers are not limited to programming languages; they also play a crucial role in parsing data, especially when the schema is only known during runtime.

To illustrate the power of JIT compilation, the author created a toy regular expression engine that supports only literal strings and repetition (i.e., the regex *). This engine was implemented using Rust structures, enabling it to handle strings such as "b(an)*" without the need for alternation or lookbehind features.

A straightforward interpreter for this regular expression engine was developed, consisting of under 20 lines of code. However, when benchmarked against a manually written version optimized for the regex, the interpreter proved to be 10-20 times slower. This stark contrast highlighted the potential for performance improvement through JIT compilation.

To leverage JIT compilation, two main steps are required. First, the assembly code for the desired runtime operations must be generated. This is achieved through a process called copy-and-patch. In this approach, predefined assembly templates, known as "stencils," are customized based on the specifics of the operation being JIT compiled. By combining these customized stencils, a program can be constructed at runtime that achieves performance comparable to manually written code.

The author demonstrates this process by generating ARM64 assembly code for the regex "b(an)*". The code is broken down into distinct sections, starting with the prologue, which initializes the program's state by setting the stack pointers. Following the prologue, the code checks for the literal string "b" and handles any non-matching characters by jumping to a fallback logic block. Subsequently, the repetition section (an)* is addressed, which involves backtracking logic to handle potential failed matches.

The final section of the generated assembly code concludes the regex by checking if the end of the string has been reached. If so, the function returns 1 to indicate a successful match; otherwise, it signifies a failed match. This JIT-compiled regular expression engine demonstrates the immense potential for performance gains when employing JIT compilation techniques.

Written by urgent.news from Lobsters's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

This story

This is one outlet's version. Read the fullest account.

Read the original at malisper.me →

More in Tech

How to Add a Human Review Gate to an n8n Lead Intake Workflow

Most lead intake automations work on the happy path. A form arrives, the workflow sends an email, and the lead appears in a CRM.

  • Human review gate added to n8n lead intake workflow
  • Failure details logged for targeted retries and prevention of sensitive data exposure

# Stopping S3 Data Exfiltration in Real Time: A Step-by-Step Incident Response

The Scenario An EC2 instance with an attached IAM role has s3:GetObject on a bucket containing sensitive data. An attacker compromises the instance, extracts temporary credentials from the metadata…

  • Identify compromised IAM role using EC2 instance ID and AWS CLI commands
  • Invalidate active sessions with inline deny policy attached to IAM role
  • Verify revocation by checking CloudTrail logs and legitimate access

The HTTP 429 That Turned Seven Minutes Into Zero Work

This is a submission for DEV's Summer Bug Smash: Smash Stories powered by Sentry . ARGUS is a data-catalog governance swarm.

  • ARGUS data-catalog system experienced seven-minute outage due to HTTP 429 error
  • System treated 429 as temporary, amplifying outage through retry loops

Stop writing the same custom HTTP wrapper in every project

Every time I start a new frontend or full-stack project, the same ritual happens. We install axios or grab native fetch, and within a few weeks, we find ourselves building a massive layer of custom…

  • Developers create custom HTTP wrappers in each project
  • Four issues addressed: flooding, payload security, TTL caching, HMAC signing
  • PHTPS library provides deduplication, caching, encryption, signing features

More from Sunday 23 August →