An optimized vc_init.rb
implementation for the official Vercel Ruby runtime that provides ~100ms faster requests while maintaining the same TypeScript runtime layer.
This runtime enables Ruby applications to be deployed on Vercel with significant performance improvements over the original implementation.
- Streamlined handler - Optimized
vc_init.rb
implementation - Minimal Ruby dependencies - Efficient use of Ruby standard library
- Faster request processing - Optimized handler logic
- Faster requests - ~100ms faster than original implementation
- Reduced memory usage - Optimized Ruby code execution
- Efficient request handling - Streamlined processing logic
The runtime uses a single vc_init.rb
file that:
-
Detects application type:
- Rack applications (
.ru
files) - UsesRack::MockRequest
for optimal performance - Custom handlers - Uses lightweight WEBrick server
- Rack applications (
-
Handles requests efficiently:
- Direct JSON parsing of Vercel's event payload
- Native Ruby HTTP method routing
- Proper encoding handling for request/response bodies
- Base64 decoding support for binary data
-
Optimizes for production:
- Sets Rails production defaults automatically
- Minimal overhead for request processing
- Clean shutdown handling
Feature | Original Runtime | Optimized Runtime |
---|---|---|
Cold Start | ~200ms | ~100ms |
Ruby Implementation | Standard handler | Optimized handler |
Request Processing | Standard flow | Streamlined flow |
Code Complexity | Multiple components | Single optimized file |
Create a config.ru
file:
require 'sinatra'
class App < Sinatra::Base
get '/' do
'Hello from optimized Ruby runtime!'
end
end
run App
Create any .rb
file with a Handler:
Handler = Proc.new do |request, response|
response.status = 200
response['Content-Type'] = 'application/json'
response.body = { message: 'Fast Ruby response!' }.to_json
end
- Ruby 3.3.x (default)
- Ruby 3.2.x
- Ruby 3.1.x
- Ruby 3.0.x
- Optimized initialization - Minimal overhead for each function invocation
- Efficient Ruby code - Leveraging Ruby 3.x performance improvements
- Simplicity wins - Streamlined implementation for better performance
- Smart handler selection - Rack apps use MockRequest, custom handlers use minimal WEBrick
MIT