Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

PHP is the language which would implement a loop by pushing a byte offset to a stack and seek in the file at the end of the loop. Massive improvement if you had a disk cache.

It's all relative to where you come from. The byte code interpreter of BEAM is very close to a poor man's JIT. It has some op-fusion, and uses threaded code. So gaining efficiency will require lot of work.



Also the languages are almost extreme opposites in terms of how they execute as they make entirely different tradeoffs.


Is the BEAM's byte code interpreter comparable to something like opcache with PHP?

[0]: https://www.php.net/manual/en/intro.opcache.php


BEAM is precompiled bytecode. The loader will peephole optimize the byte code replacing some instruction sequences with optimized variants. Bytecode resides in memory already, and there is no disk seeking.


> PHP is the language which would implement a loop by pushing a byte offset to a stack and seek in the file at the end of the loop.

I didn't quite understand this. Is it some famous PHP implementation thing?


It's from one of the first implementations of the language. If you want to move fast, and you have no ambition about execution speed, this is a solution to the problem of implementing loops.

PHP worked by parsing code directly from the file for every executed statement. So you ran the full lex->parse->interpret path for each statement. A loop need to jump back, which can be tracked by the file offset position, so you can redo the lex->parse->interpret step for the loops statements again.

Modern PHP will not do this, because it's highly inefficient. I'm not even sure it survived into the 2000's.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: