Press "Enter" to skip to content

Yaconf 1.1 — the 40% faster release

Yaconf is a high-performance PHP configuration container. At PHP startup it parses the INI-format config file and stores the result in PHP's resident memory, so there's no need to re-parse the config file on every request; and it reads config values "zero-copy". For the original introduction, see the one I wrote when it was released in 2015: Yaconf - A high-performance configuration management extension.

Yaconf is used heavily on Weibo and has been running stably for years, but since its release in 2015 there has been little in the way of major changes.

Recently, thanks to the quarantine, I did a series of refactoring on Yaconf, mainly to reduce memory usage during value retrieval — essentially rewriting the overall logic. So how did the performance optimization turn out? Let's do a simple benchmark.

First, the test config file:

name="yaconf"
version="1.1.0"

[author]
name="Laruence"
blog.address="https://www.laruence.com"

[developer : author]
projects.yaf.repo="https://github.com/laruence/yaf"

The benchmark script:

<?php
function bench($key) {
	$count = 1000000;
	$start = microtime(true);
	while ($count--) {
		Yaconf::get($key);
	}
	printf("%s: %fsn", $key, microtime(true) - $start);
}

bench("config.name");
bench("config.author.name");
bench("config.author.blog.address");
bench("config.developer.projects.yaf.repo");
?>

First, testing with yaconf-1.0.8:

config.name: 0.129616s
config.author.name: 0.172129s
config.author.blog.address: 0.206659s
config.developer.projects.yaf.repo: 0.248205s

Then, testing with yaconf-1.1.0:

config.name: 0.075837s
config.author.name: 0.098553s
config.author.blog.address: 0.144033s
config.developer.projects.yaf.repo: 0.144580s

You can see that retrieving config values now takes on average 40% less time, especially when you use the chain method to fetch config content — the longer the chain, the more pronounced the improvement.

That's it. Yaconf-1.1.0 has been released to PECL: Yaconf

enjoy!

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.