Blog by nikic. Find me on GitHub, StackOverflow and Twitter. Learn more about me.

This year in LLVM (2023)

Summary of my work on LLVM in 2023.

How to reduce LLVM crashes

Step-by-step guide on how to reduce LLVM crashes.

LLVM: Scalar evolution

A brief introduction to LLVM's scalar evolution analysis, which models how values change inside loops.

LLVM: Canonicalization and target-independence

This documents LLVM's design philosophy when it comes to target-dependence in the middle-end optimizer.

LLVM: The middle-end optimization pipeline

A high-level overview of LLVM's middle-end optimization pipeline and some of the design considerations behind it.

This year in LLVM (2022)

Summary of my work on LLVM in 2022.

The opcache optimizer

An introduction to the inner workings of the opcache optimizer, or at least some parts of it.

Type variance in PHP

Type variance allows types to change during inheritance in a way that is compatible with the Liskov substitution principle. This article describes how this works on a technical level.

Early binding in PHP

Early binding allows using a class before its declaration in the same file. However, the precise behavior is rather arcane.

How opcache works

A brief overview of how the PHP opcache extension works, covering the caching-related aspects only.

Design issues in LLVM IR

Discusses a number of design issues related to IR canonicality: Pointer element types, type-based GEP, and constant expressions.

Make LLVM fast again

Introduces a compile-time tracking service for LLVM, and some specific compile-time improvements I have implemented.

PHP 7 Virtual Machine

An overview of the PHP virtual machine.

Internal value representation in PHP 7 - Part 2

Covers the implementation of complex types like strings and objects in PHP 7, as well as a number of special types like indirect zvals.

Internal value representation in PHP 7 - Part 1

Describes and compares the zval implementations used by PHP 5 and PHP 7, including a discussion of references. Other types are covered in the next part.

PHP's new hashtable implementation

In this article we'll explore how the new hashtable implementation used by PHP 7 improved memory usage and performance.

Methods on primitive types in PHP

This article discusses the merits of allowing method calls on primitive PHP types, like strings and arrays.

Fast request routing using regular expressions

This article describes a number of techniques to improve performance of regular expression based dispatch processes, as used in request routing or lexing.

The case against the ifsetor function

The ifsetor function can be used to suppress notices when accessing array indices. This post discusses some of the issues this function has and how to resolve them.

Cooperative multitasking using coroutines (in PHP!)

This post explains how coroutines can be used for task scheduling and handling asynchronous operations in a synchronous-seeming way.

Are PHP developers functophobic?

PHP developers don't seem to like normal functions much. I think that this is related to the one-to-one class to file mapping that PHP has inherited from Java.

How to add new (syntactic) features to PHP

In this post I'm describing how one can add new syntax to PHP. At the same time, this post can be seen as a general introduction to the workings of the Zend Engine.

What PHP 5.5 might look like

PHP 5.5 is still in an early development stage, but there are already many proposals that are being worked on. This post gives some insights into the recent developments.

A plea for less (XML) configuration files

Configuration files typically use XML or some other domain specific language. But why? Why not just use the usual programming language instead?

PHP solves problems. Oh, and you can program with it too!

PHP is a great language to start programming. And once you started, PHP is also good for "real" programming. So what's the problem?

The true power of regular expressions

There is a major misunderstanding about what modern regular expression implementation can or cannot do. This article analyses the situation by walking through the different grammar classes.

Understanding PHP's internal array implementation (PHP's Source Code for PHP Developers - Part 4)

The fourth part of the "PHP's Source Code for PHP Developers" series, covering how arrays are internally implemented in PHP and how they are used in the source code.

PHP's Source Code for PHP Developers - Part 3 - Variables

Cross-link to the third part of the "PHP's Source Code for PHP Developers" series, covering how PHP values are represented internally and used throughout the source code.

Understanding PHP's internal function definitions (PHP's Source Code for PHP Developers - Part 2)

The second part of the "PHP's Source Code for PHP Developers" series, covering how to find functions in the PHP source code and how they are structured.

Scalar type hinting is harder than you think

A quick overview of the different scalar type hinting proposals and why PHP is having such a hard time deciding.

Pointer magic for efficient dynamic value representations

JS implementations use some neat tricks to achieve good performance. One of those tricks is a good bit of pointer magic to make dynamically typed values more efficient.

htmlspecialchars() improvements in PHP 5.4

There is some nice new stuff for htmlspecialchars() in PHP 5.4, which hasn't yet got the attention it deserves.

Careful: XDebug can skew your performance numbers

In some cases XDebug can significantly skew your benchmarking and profiling numbers. So make sure that you do measurements without it.

Disproving the Single Quotes Performance Myth

One of the oldest myths around PHP is that single quotes are faster than double quotes. And. It. Is. Not. True.

Supercolliding a PHP array

Inserting 65536 specially crafted values into a PHP array can take 30 seconds, whereas normally it would only take 0.01 seconds.

Don't be STUPID: GRASP SOLID!

Introducing STUPID: Singleton, Tight Coupling, Untestability, Premature Optimization, Indescriptive Naming, Duplication.

How big are PHP arrays (and values) really? (Hint: BIG!)

PHP's memory usage might seem atrocious to some - twenty times more than the optimum you would have in C. This post tries to explain those numbers and why they are necessary.

PCRE and newlines

There is a huge number of newline related features in PCRE (regular expressions) that nearly nobody knows about. I want to shed light on some of those.

Manually installing PEAR on Windows

If you ever tried to install PEAR on Windows you probably know what a woeful task it is. This is a short instruction on how to manually install PEAR (without using go-pear.phar).

PHP internals: When does foreach copy?

PHP's foreach language construct sometimes copies the array it iterates and sometimes does not. This post analyzes when and why this happens.

Improving lexing performance in PHP

Some thoughts on improving lexing performance in PHP by compiling the individual token regexes into one big super-regex.