Comments (3)
Interesting 🤔
Just to be clear: The error with the timeout is to be expected, as it is in milliseconds.
I got curious and removed the IO-related part and using just Kernel.sleep
having rescue
in the attached method does influence the runtime quite a bit. In the following code with mini_racer timeout at 10ms, but sleeping for 1000ms. With rescue
we need ~2 seconds, without ~12.78ms (slightly above the 10ms timeout we set):
# frozen_string_literal: true
require "bundler/inline"
gemfile do
source "https://rubygems.org"
gem "mini_racer", "0.12.0"
end
require "libv8-node"
puts "RUBY_VERSION : #{RUBY_VERSION}"
puts "RUBY_PLATFORM: #{RUBY_PLATFORM}"
puts "MiniRacer::VERSION: #{MiniRacer::VERSION}"
puts "Libv8::Node::LIBV8_VERSION: #{Libv8::Node::LIBV8_VERSION}"
puts "=" * 80
def sleep_rescue(duration_ms)
sleep duration_ms.to_f / 1000
:result_a
rescue MiniRacer::ScriptTerminatedError => e
puts "attached: TIMEOUT! #{e.class} - #{e.message}"
:timeout
rescue => e
puts "attached: ERROR: #{e.class} - #{e.message}"
end
def sleep_no_rescue(duration_ms)
sleep duration_ms.to_f / 1000
:result_b
end
js_context = MiniRacer::Context.new(timeout: 10)
js_context.attach("sleep_rescue", method(:sleep_rescue))
js_context.attach("sleep_no_rescue", method(:sleep_no_rescue))
started = Time.now
puts "sleep_rescue:"
begin
result = js_context.call("sleep_rescue", 1000)
puts "RESULT: #{result}"
rescue => e
puts "ERROR: #{e.class} - #{e.message}"
end
puts "==> #{Time.now - started} sec"
puts
started = Time.now
puts "sleep_no_rescue:"
begin
result = js_context.call("sleep_no_rescue", 1000)
puts "RESULT: #{result}"
rescue => e
puts "ERROR: #{e.class} - #{e.message}"
end
puts "==> #{Time.now - started} sec"
resulting in this printed:
RUBY_VERSION : 3.3.1
RUBY_PLATFORM: arm64-darwin23
MiniRacer::VERSION: 0.12.0
Libv8::Node::LIBV8_VERSION: 11.8.172.17
================================================================================
sleep_rescue:
attached: TIMEOUT! MiniRacer::ScriptTerminatedError - Terminated during callback
RESULT: timeout
==> 2.01841 sec
sleep_no_rescue:
ERROR: MiniRacer::ScriptTerminatedError - Terminated during callback
==> 0.012784 sec
from mini_racer.
Thank you for such a detailed answer ! I had completely missed the fact that the timeout was in ms. I am very curious as to why the rescue would also impact such a delay, exceptions are often costly, but I wouldn't have imagined to that extent 🤔
from mini_racer.
I have not figured out where the time is spent exactly, but it is not in the Ruby method (added some crude debug statements in mini_racer directly). I'm suspecting this is happening in C-land somewhere, but that's out of reach for me to understand further.
That might be something @SamSaffron or @lloeki might be able to help better. IMO the huge delay is a bug.
from mini_racer.
Related Issues (20)
- After MacOS Ventura upgrade. gem install works, bundle install does not HOT 2
- Context has no Isolate available anymore HOT 3
- bundler install error HOT 5
- Installing mini_racer 0.6 on docker M1 fails with "make: printf: Argument list too long" HOT 4
- Update default branch to `main` HOT 3
- Unexpected token p in JSON at position HOT 2
- Gem::Ext::BuildError: ERROR: Failed to build gem native extension (Ruby 2.7.4) HOT 3
- Discuss: Release version 1.0.0 and manage consumer breaking version expectations HOT 3
- Node release catch-up plan HOT 42
- CI Improvements HOT 1
- `Isolate::low_memory_notification` fails to lock Isolate HOT 5
- Error installing mini_racer: ERROR: Failed to build gem native extension HOT 7
- Undefined Conversion
- Segmentation fault when application stops (Ruby 3.2.2, tcmalloc or jemalloc) HOT 17
- mini_racer not starting: `ZSt28__throw_bad_array_new_lengthv: symbol not found (LoadError)` HOT 9
- Suggestions for context defaults for server side rendering HOT 4
- Security guarantees? HOT 1
- mini_racer 0.12.0 Segmentation fault on x86_64-linux with libv8-node 21.7.2.0 HOT 101
- mini_racer can't install on ubuntu 24 using ruby 3.2.3 and bundler 2.5.13 HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mini_racer.