Nikita Popov

nikic.github.io · Personal blog · on HN since 2013

Nikita Popov, a PHP and LLVM contributor, writes about regular expressions, PHP internals and compiler performance.

What HN saysCommenters cite it for the regex expressive power article, fast routing with regular expressions, and PHP's hashtable implementation.
51HN people shared it
23linked it in comments
34stories submitted
1.7Kstory points
6 years agolast shared
2013people per year2026

Most-shared posts

  1. 1
    The true power of regular expressions (2012)
    10 people · 367 points · first shared 2013 · 38 comments on HN
  2. 2
    Make LLVM Fast Again
    9 people · 589 points · first shared 2020 · 235 comments on HN
  3. 3
    Fast request routing using regular expressions
    7 people · 66 points · first shared 2014 · 41 comments on HN
  4. 4
    PHP 7's new hashtable implementation
    5 people · 254 points · first shared 2014 · 131 comments on HN
  5. 5
  6. 6
    PHP 7 Virtual Machine
    3 people · 371 points · first shared 2017 · 125 comments on HN
  7. 7
    [PHP] Cooperative multitasking using coroutines
    3 people · 6 points · first shared 2013 · discussion on HN
  8. 8
    PHP solves problems. Oh, and you can program with it too
    2 people · 6 points · first shared 2014 · 2 comments on HN
  9. 9
    Methods on primitive types in PHP
    2 people · 3 points · first shared 2014 · discussion on HN
  10. 10
    Internal value representation in PHP 7 – Part 2
    2 people · 2 points · first shared 2015 · discussion on HN
  11. 11
    Internal value representation in PHP 7, part 1
    1 people · 65 points · first shared 2015 · 11 comments on HN
  12. 12
    Make LLVM Fast Again
    1 people · 4 points · first shared 2020 · discussion on HN
  13. 13
    PHP 7 Virtual Machine
    1 people · 2 points · first shared 2017 · discussion on HN
  14. 14
    Careful: XDebug can skew your performance numbers
    1 people · 1 points · first shared 2013 · discussion on HN
  15. 15
    Don't be STUPID: GRASP SOLID
    1 people · 1 points · first shared 2013 · discussion on HN

What HN people wrote when they linked it

babyrainbow · 2016-10-14
>JavaScript suffers the same hate today.. The difference between Php and Javascript is that Javascript have competent people driving it forward. Php is still developed by college students with no real world programming experience, in their spare time.... Downvotes? Don't think this is true? See the following. These are couple of most prominent people working in the language. [1] https://nikic.github.io/aboutMe.html [2] https://ajf.me/
jdnier · 2016-09-09
For some great exposition on what "regular" actually means, check out http://nikic.github.io/2012/06/15/The-true-power-of-regular-expression… "Thus the question arises: Can regular expressions match only regular grammars, or can they also match more? The answer to this is both yes and no"...
nubs · 2014-05-29
The claim of "fast" definitely looks inaccurate in comparison to nikic's router[0]. I'd recommend reading through his blog[1] on the matter. [0]: https://github.com/nikic/FastRoute [1]: http://nikic.github.io/2014/02/18/Fast-request-routing-using-regular-e…
TheZenPsycho · 2013-08-19
the answer if you're using perl or pcre, is probably yes, but for the love of djikstra don't ever do it. This was on HN a while back: http://nikic.github.io/2012/06/15/The-true-power-of-regular-expression…
masklinn · 2020-02-07
Interestingly enough here it was kinda but kinda not the other way around: historically PHP used a closed-addressing hash map and threaded a doubly linked list through it to maintain the insertion order. But the dict TFA talks about doesn't use a doubly linked list, or closed addressing, its ordering is a side-effect of its implementation but not originally a core goal (memory saving and iteration speed were). It'd probably been proposed by others before but it came to wider attention after Raymond Hettinger (a core dev) proposed it a few years back[0]. PHP actually released it first[1], closely followed by pypy[2]. CPython only got around to it some time later[3] [0] https://mail.python.org/pipermail/python-dev/2012-December/123028.html [1] https://nikic.github.io/2014/12/22/PHPs-new-hashtable-implementation.h… [2] https://morepypy.blogspot.com/2015/01/faster-more-memory-efficient-and… [3] https://docs.python.org/3/whatsnew/3.6.html?highlight=3.6#whatsnew36-c…
smasher164 · 2021-01-13
There isn't any evidence to suggest this. Slow compilation speed is mostly a consequence of priorities. See https://nikic.github.io/2020/05/10/Make-LLVM-fast-again.html and https://www.reddit.com/r/haskell/comments/45q90s/is_anything_being_don… Sure, there are some language features that can make optimizations pathological complex, but for the most part if compilation speed isn't continuously tracked and strictly enforced against new changes, you inevitably regress into a slower compiler. For instance, the Go community is highly sensitive to compilation speed. Although the Go compiler is SSA-based like LLVM, it's very selective about the optimizations applied. The Go compiler tracks and benchmarks each phase of the compiler release-to-release to identify major regressions.
roblabla · 2020-11-18
The rust compiler team now tracks LLVM performance, see [0]. They are able to spot regressions as soon as they get merged, and petition to get the change reverted or performance fixed when the impact is large. This has been fairly successful so far, but obviously needs sustained efforts if we are to ever dream of ever getting halfway decent compilation times. [0]: https://nikic.github.io/2020/05/10/Make-LLVM-fast-again.html
MinusGix · 2020-08-05
The linked llvm article about performance ( https://nikic.github.io/2020/05/10/Make-LLVM-fast-again.html ) says: "Rust does this by running a set of benchmarks on every merge, with the data available on perf.rust-lang.org. Additionally, it is possible to run benchmarks against pull requests using the @rust-timer bot. This helps evaluate changes that are intended to improve compile-time performance, or are suspected of having non-trivial compile-time cost." So, they do seem to have a bot to perform such tests, though I have no clue how often they use it.
daoxid · 2020-08-05
In a linked blog post [0] and on the Rust performance page [1] the performance metric "instructions" is used. What exactly is meant by that? Number of instructions executed? [0] https://nikic.github.io/2020/05/10/Make-LLVM-fast-again.html [1] https://perf.rust-lang.org/
dodobirdlord · 2020-05-24
Possibly, I'm no professional compiler author. But I imagine doing so would require templatizing a lot of logic, and would significantly slow down the compilation of the compiler itself, which is an important metric for development velocity of compiler improvements. (The linux kernel is famous for taking about the same amount of time to compile through its history. If compile times get long enough people start paying attention to optimizing compile time instead of performance.) It was eye-opening when I read this blog post and learned that LLVM spends about 0.4% of all compilation time reading the bytes of the string "null-pointer-is-valid" over and over. Hot code paths can be pretty hot. https://nikic.github.io/2020/05/10/Make-LLVM-fast-again.html
aaronedam · 2020-05-08
Those are some opinionated tests for performance checks. What both symfony and laravel routers achieve with their routers isn't comparable with this router library. If you want to go a bit further and implement ultimate fastest routing, create an associative array, routes as key, callable's as value. Will it be fast, yes. Will it be usable, no. For more information about routing, plase see Nikita Popov(nikic)'s post about FastRoute. http://nikic.github.io/2014/02/18/Fast-request-routing-using-regular-e…
cben · 2017-09-01
Nice article covering both tagged integers and pointers in NaN: https://nikic.github.io/2012/02/02/Pointer-magic-for-efficient-dynamic… Copy of Mozilla's article presenting their switch to NaN tagging: https://evilpie.github.io/sayrer-fatval-backup/cache.aspx.htm#post-485 HN discussion with more history & links: https://news.ycombinator.com/item?id=1569825
falcolas · 2016-05-17
Well, considering the PCRE regexes are nearly Turing complete, you can parse (well formed) HTML. Someone better versed than I: https://nikic.github.io/2012/06/15/The-true-power-of-regular-expressio… Of course, the money quote is: Just because you can, doesn’t mean that you should.
TazeTSchnitzel · 2015-02-18
A good portion of PHP 7's performance improvements came from better structure packing: https://wiki.php.net/phpng-int http://nikic.github.io/2014/12/22/PHPs-new-hashtable-implementation.ht…
hornetblack · 2014-09-24
It's not a regular grammar. Regular expressions were designed to handle regular grammar, and there are cases where something that looks valid is actually invalid: [email protected]. (See the above posters link: https://nikic.github.io/2012/06/15/The-true-power-of-regular-expressio…
wvenable · 2014-02-01
I disagree. Strict type hinting would be ridiculous in PHP and lead to a lot of unnecessary and unsafe casting. nikic goes through all the scalar type hint options here: http://nikic.github.io/2012/03/06/Scalar-type-hinting-is-harder-than-y… Strict weak type hinting seems like the most realistic and pragmatic choice except I would add a cast to make sure the type is actually an `int` in the function.
JelteF · 2013-08-30
True for official regular expressions, but not for the ones used in most programming languages. http://nikic.github.io/2012/06/15/The-true-power-of-regular-expression…
mh- · 2013-05-26
fair point, but they're rather costly due to the amount of memcpy'ing in my experience.. you've probably seen/know this, given that you know PHP internals :), but for others: http://nikic.github.io/2011/12/12/How-big-are-PHP-arrays-really-Hint-B…
conradev · 2020-07-16
But I don't think that it has _anything_ to do with the individual programmers inherently understanding performance better. There is likely a huge organizational focus on performance and more people expressly dedicated to the task because it is a higher priority for Epic. It is directly correlated to Epic's ability to deliver a successful product to game companies, whereas for browsers it is slightly more orthogonal to their success. LLVM has a bunch of contributors who likely understand the intricacies of machine code better than either of us, and: > Each LLVM release is a few percent slower than the last. > The larger problem is that LLVM simply does not track compile-time regressions. While LNT tracks run-time performance over time, the same is not being done for compile-time or memory usage. The end result is that patches introduce unintentional compile-time regressions that go unnoticed, and can no longer be easily identified by the time the next release rolls out. https://nikic.github.io/2020/05/10/Make-LLVM-fast-again.html
nindalf · 2020-05-15
It probably will. Every release has a number of performance improvements although the release notes don't mention them. Great work like [1] [2] [3] weren't mentioned in the release notes because those notes mostly focused on feature improvements. This work seems to be gaining momentum, if anything. The next version (1.44) will significantly improve the performance of programs that use async [4]. The next version of LLVM will be faster [5] (hopefully reversing the perf regressions in LLVM 10). [1] - https://blog.mozilla.org/nnethercote/2020/04/24/how-to-speed-up-the-ru… [2] - https://blog.mozilla.org/nnethercote/2019/12/11/how-to-speed-up-the-ru… [3] - https://blog.mozilla.org/nnethercote/2019/10/11/how-to-speed-up-the-ru… [4] - https://ferrous-systems.com/blog/stable-async-on-embedded/ [5] - https://nikic.github.io/2020/05/10/Make-LLVM-fast-again.html
capn_cabbage · 2019-11-10
I believe it is just a naming issue. Not even sure that PHP devs have agreed on how to name the type. Internally, PHP calls them both arrays and hash tables if I understand correctly. In Zend/zend_types.h[1] of PHP source: typedef struct _zend_array zend_array; typedef struct _zend_array HashTable; struct _zend_array { ... }; That being said AFAICT, HashTable and zend_array are used interchangeably throughout the source. I am not a C programmer, but I did write a couple of PHP extensions and that was my general understanding. Perhaps it is a compatibility issue or just used to abstract types differently in various areas of the C API. Check out [2] for a deeper understanding of how arrays are handled internally in PHP. [1]: https://github.com/php/php-src/blob/php-7.3.11/Zend/zend_types.h [2]: https://nikic.github.io/2014/12/22/PHPs-new-hashtable-implementation.h…
l-p · 2014-09-24
Please read this : https://nikic.github.io/2012/06/15/The-true-power-of-regular-expressio… RFC5322-compliant regex: / (?(DEFINE) (?<addr_spec> (?&local_part) @ (?&domain) ) (?<local_part> (?&dot_atom) | (?&quoted_string) | (?&obs_local_part) ) (?<domain> (?&dot_atom) | (?&domain_literal) | (?&obs_domain) ) (?<domain_literal> (?&CFWS)? \[ (?: (?&FWS)? (?&dtext) )* (?&FWS)? \] (?&CFWS)? ) (?<dtext> [\x21-\x5a] | [\x5e-\x7e] | (?&obs_dtext) ) (?<quoted_pair> \\ (?: (?&VCHAR) | (?&WSP) ) | (?&obs_qp) ) (?<dot_atom> (?&CFWS)? (?&dot_atom_text) (?&CFWS)? ) (?<dot_atom_text> (?&atext) (?: \. (?&atext) )* ) (?<atext> [a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+ ) (?<atom> (?&CFWS)? (?&atext) (?&CFWS)? ) (?<word> (?&atom) | (?&quoted_string) ) (?<quoted_string> (?&CFWS)? " (?: (?&FWS)? (?&qcontent) )* (?&FWS)? " (?&CFWS)? ) (?<qcontent> (?&qtext) | (?&quoted_pair) ) (?<qtext> \x21 | [\x23-\x5b] | [\x5d-\x7e] | (?&obs_qtext) ) # comments and whitespace (?<FWS> (?: (?&WSP)* \r\n )? (?&WSP)+ | (?&obs_FWS) ) (?<CFWS> (?: (?&FWS)? (?&comment) )+ (?&FWS)? | (?&FWS) ) (?<comment> \( (?: (?&FWS)? (?&ccontent) )* (?&FWS)? \) ) (?<ccontent> (?&ctext) | (?&quoted_pair) | (?&comment) ) (?<ctext> [\x21-\x27] | [\x2a-\x5b] | [\x5d-\x7e] | (?&obs_ctext)…

Keyboard shortcuts

/Search
j kNext / previous blog
EnterOpen selected blog
vVisit the blog site
fFollow / unfollow
lSwitch grid / list view
dSwitch dark mode
g hHome
g pTop posts
g tTopics
g fFollowing
g lLiked
g yHistory
g qFAQ
EscBack / close