All Projects → jhawthorn → Execjs Fastnode

jhawthorn / Execjs Fastnode

Licence: mit
⚡️ A faster Node.JS integration for Ruby/Rails ExecJS

Programming Languages

javascript
184084 projects - #8 most used programming language
ruby
36898 projects - #4 most used programming language

Labels

Projects that are alternatives of or similar to Execjs Fastnode

Drafting
Ruby gem for saving drafts of ActiveRecord models
Stars: ✭ 41 (-16.33%)
Mutual labels:  rails
Drag and drop active storage
A demo drag and drop image upldate Ruby on Rails app using Stimulus.js, DropZone.js, and ActiveStorage
Stars: ✭ 46 (-6.12%)
Mutual labels:  rails
Modern Datatables
They are many ways to build reactive web interfaces but do we really need to add the complexity of JavaScript frameworks like Vue.js or React?
Stars: ✭ 48 (-2.04%)
Mutual labels:  rails
Nerdnews
A free and open source social news website focusing on computer science and FOSS news for Persian community
Stars: ✭ 41 (-16.33%)
Mutual labels:  rails
Super
A simple, powerful, single dependency Rails admin framework
Stars: ✭ 43 (-12.24%)
Mutual labels:  rails
Graphql Rails Generators
Graphql Rails Scaffold™. Automatically generate GraphQL types from your rails models.
Stars: ✭ 47 (-4.08%)
Mutual labels:  rails
Sorcery
Magical Authentication
Stars: ✭ 998 (+1936.73%)
Mutual labels:  rails
Raygun Rails
Rails 6 application template for Raygun, the Carbon Five Rails application generator.
Stars: ✭ 48 (-2.04%)
Mutual labels:  rails
Mina Unicorn
Unicorn tasks for Mina
Stars: ✭ 44 (-10.2%)
Mutual labels:  rails
Wheelmap
♿️ Source code of classic wheelmap.org (deprecated)
Stars: ✭ 47 (-4.08%)
Mutual labels:  rails
Ml competition platform
Kaggle-like machine learning competition platform
Stars: ✭ 42 (-14.29%)
Mutual labels:  rails
Paranoia uniqueness validator
Stars: ✭ 42 (-14.29%)
Mutual labels:  rails
App
Fast and searchable Ruby docs
Stars: ✭ 47 (-4.08%)
Mutual labels:  rails
Ar Uuid
Override migration methods to support UUID columns without having to be explicit about it.
Stars: ✭ 41 (-16.33%)
Mutual labels:  rails
Rails stimulus flatpickr
Advanced datepicking example app with Stimulus + Flatpickr + Turbolinks
Stars: ✭ 48 (-2.04%)
Mutual labels:  rails
Hours
Time registration that doesn't suck
Stars: ✭ 1,003 (+1946.94%)
Mutual labels:  rails
Furatto Rails Start Kit
A rails app with Furatto, Devise, and Facebook Authentication perfect for hackathons!
Stars: ✭ 46 (-6.12%)
Mutual labels:  rails
Rackula
Generate a static site from any rack middleware.
Stars: ✭ 49 (+0%)
Mutual labels:  rails
Monarchy
Hierarchical access management system with advanced roles inheritance. 🦋
Stars: ✭ 48 (-2.04%)
Mutual labels:  rails
Rapporteur
A Rails Engine which provides a customizable status page on your application.
Stars: ✭ 47 (-4.08%)
Mutual labels:  rails

ExecJS FastNode

What's this?

An alternative implementation of ExecJS's Node.js integration. This aims to speed up sprockets compilation without needing to embed a javascript interpreter inside of ruby like therubyracer.

How much faster is it?

Much.

$ rake bench
...
                    user       system     total      real
Node.js (V8) fast   0.000000   0.000000   0.000000   (0.069723)
therubyracer (V8)   0.020000   0.000000   0.020000   (0.018010)
Node.js (V8)        0.000000   0.010000   1.470000   (1.487579)

Okay, so it's not as fast as therubyracer, but it's 20x faster than the standard ExecJS Node.js implementation.

The benchmark measures the time to compile the javascript CoffeeScript compiler and then eval a small snippet 10 times.

How?

The existing ExecJS runtime has to run a new Node.js process each time any JS is to be run. This means that if you are loading up the CoffeeScript compiler in order to compile some sprockets assets, it needs to reload the node executable and the entire coffeescript compiler for each file it is compiling.

This implementation avoids this by starting a persistently running Node.js process connected through a UNIX socket. Isolation between different ExecJS contexts is achieved through Node's vm.Script.

ExecJS FastNode Standard ExecJS Node

Is this production ready?

Maybe? It needs more testing to be labeled as such. If you encounter any troubles please file an issue.

Currently minimal effort is made to handle catastrophic errors: Node.js crashing, running out of memory, being killed.

It's probably fine for development.

Installation

Add this line to your application's Gemfile:

gem 'execjs-fastnode'

And then bundle install. You know the drill.

You can verify that this runtime is being autodetected and used by checking ExecJS.runtime in a console.

You can force a certain runtime to be used using EXECJS_RUNTIME=FastNode

$ EXECJS_RUNTIME=FastNode bin/console
> ExecJS.runtime
=> #<ExecJS::FastNode::ExternalPipedRuntime:0x005599c0d38740 @name="Node.js (V8) fast"...

$ EXECJS_RUNTIME=Node bin/console
> ExecJS.runtime
=> #<ExecJS::ExternalRuntime:0x00559c440347c0 @name="Node.js (V8)" ...

Why not upstream this to execjs?

I'd like to, but it will take time. The goal of this endeavour is to give users a fast ExecJS runtime without needing any additional dependencies, just a Node.js installation. However most users don't (and shouldn't have to) think about ExecJS and need it to Just Work. This is a pretty significant change and it probably won't "Just Work" right now, and more time is needed to tell if it can.

I have sent a pull request upstream to use vm.runInContext, which would be the first step to merging this upstream.

Why not just use therubyracer?

Maybe you should, if you need the speed.

Heroku recommends againts it as do various stack overflow answers with vague mentions of high memory usage. I haven't seen any benchmarks or bug reports that demonstrate this, so I consider these claims somewhat suspect.

mini_racer is another option.

The ExecJS Node runtime has its benefits as well. It should work on jRuby and other non-MRI runtimes. If this were merged upstream it would give developers fast javascript execution without needing an extra gem or configuration, just a working node somewhere in $PATH.

Limitations

  • Syntax errors on Node.js versions 0.10.x and 4.x can't report the exact line number of the error. Instead they will always display (execjs):1.
  • This only runs a single node process, so javascript execution can only make use of a single processor. This isn't much of an issue because sprockets doesn't parallelize builds. This runtime is so much faster than the original that this would only be an issue with very specific use cases.

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/jhawthorn/execjs-fastnode.

License

The gem is available as open source under the terms of the MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].