phpv8 / v8js

V8 Javascript Engine for PHP — This PHP extension embeds the Google V8 Javascript Engine
http://pecl.php.net/package/v8js
MIT License
1.84k stars 200 forks source link

Airbnb Hypernova #353

Closed aftabnaveed closed 6 years ago

aftabnaveed commented 6 years ago

Today I came across this view rendering service by Airbnb https://github.com/airbnb/hypernova wherein their FAQs they say:

Isn‘t sending an HTTP request slow?

There isn‘t a lot of overhead or latency, especially if you keep the servers in close proximity to each other. It‘s as fast as compiling many ERB templates and gives you the benefit of unifying your view code.

Why not an in-memory JS VM?

This is a valid option. If you‘re looking for a siloed experience where the JS service is kept separate, then Hypernova is right for you. This approach also lends itself better to environments that don‘t already have a JS VM available.

Since PHP V8js is in memory solution as opposed to the hypernova by Airbnb I wonder if anyone has benchmarked the results? I doubt that any HTTP connection will be faster than in-memory solution like v8js.

stesie commented 6 years ago

Personally I haven't done any benchmarking with regard to that.

Yet I wouldn't want to bet on which method is faster; probably both have their advantages.

I agree that per se the HTTP connection adds some overhead, yet hypernova is a service that keeps running for a while ... and hence V8's JIT will kick in an probably yield faster code. Also you don't have to care for small startup times as V8 isn't reinitialized on each and every request.

Yet setup with in-memory VM is probably easier (once you have php-v8js running) as there are no external dependencies (which might not be available when needed). However you have to especially take care for specialized heap snapshots so that (lack of) startup performance doesn't bite you.