Skip to content

Improve ruby performance#1873

Open
naomichi-y wants to merge 3 commits intodherault:masterfrom
naomichi-y:feature/improve-ruby-performance
Open

Improve ruby performance#1873
naomichi-y wants to merge 3 commits intodherault:masterfrom
naomichi-y:feature/improve-ruby-performance

Conversation

@naomichi-y
Copy link
Contributor

@naomichi-y naomichi-y commented Feb 13, 2026

Description

This PR improves the Ruby runtime performance in serverless-offline by adopting a persistent process model, and adds hot-reload support for local development.

  • Previously, every HTTP request spawned a new ruby invoke.rb process via execa(), executed the handler, and then the process exited.
  • Now, a single Ruby process is spawned once when RubyRunner is constructed. The process runs in a persistent loop, reading JSON payloads from stdin and writing results to stdout. Subsequent invocations reuse the same process by writing to stdin.
  • The handler module is require'd once at Ruby process startup, eliminating interpreter initialization and file loading overhead on every invocation.

Hot reload support

  • Added a rubyWatchDirs option. When specified, the runner watches the given directories for .rb file changes and automatically restarts the Ruby process.
  • Restarts are debounced (100ms) to avoid redundant restarts on rapid file saves.
  • If a restart is triggered while a request is in-flight (#busy), it is queued and executed after the current invocation completes.

Motivation and Context

The Ruby runner was the only runtime that spawned a new OS process on every Lambda invocation. This caused significant latency overhead during local development, especially for runtimes with slow startup (e.g., gems with native extensions). The Python runner already used the persistent process pattern; this PR brings the Ruby runner to parity.

The hot-reload feature improves the local development experience by automatically reflecting .rb file changes without requiring a manual restart of serverless-offline.

How Has This Been Tested?

  • Manually tested by running a Ruby Lambda function locally with serverless-offline and sending repeated HTTP requests, confirming that the Ruby process is spawned only once and responses are returned correctly across multiple invocations.
  • Tested hot-reload by modifying a .rb handler file while serverless-offline is running with rubyWatchDirs configured, confirming that the Ruby process restarts and subsequent requests use the updated handler.
  • Existing integration tests under tests/integration/docker/ruby/ pass without modification.

Screenshots (if appropriate):

N/A

@DorianMazur DorianMazur force-pushed the feature/improve-ruby-performance branch from 29f9064 to 1aaa866 Compare February 24, 2026 13:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant