# Code Review: LightBinding5

**URL:** <https://www.ruby-forum.com/t/code-review-lightbinding5/181521>\
**Category:** IronRuby\
**Created:** [January 13, 2010, 5:12am UTC](https://www.ruby-forum.com/t/code-review-lightbinding5/181521 "2010-01-13T05:12:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![grujildo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/94ad74/32.png) [@grujildo](https://www.ruby-forum.com/u/grujildo)\
**Post date:** [January 13, 2010, 5:12am UTC](https://www.ruby-forum.com/t/code-review-lightbinding5/181521/1 "2010-01-13T05:12:42Z")

</div>

tfpt review “/shelveset:LightBinding5;REDMOND\tomat”

The changeset focuses on reducing time spent in JIT to compile generic  
instantiations of various helper methods. These are mostly related to  
generic instructions that implement dynamic sites and method calls. It  
reduces the number of methods jitted during startup time of irb from 481  
to 80 (with -X:CompilationThreshold 10000000), which translates to 34%  
time reduction:

rbr -X:CompilationThreshold 10000000 i.rb \< exit.txt

## i.rb:

## s = Time.now require ‘irb’ IRB.start( **FILE** ) t = Time.now p t - s

Before: 0.961096 seconds  
After: 0.631063 seconds

DLR

Adds LightDynamicExpression - these reducible nodes reduce to strongly  
typed DynamicExpressions yet when interpreted use untyped dynamic sites  
(sites typed to CallSite\<Func\<CallSite, object\*\>\>). Using light sites  
avoids jitting generic instantiations of various instructions, stubs and  
helpers that are strongly typed to the call-site signature. Also,  
strongly typed delegate types are created only when compiling the sites.

Adds helpers to CallInstruction that add MethodInfo to CallInstruction  
mapping into the internal cache. These helpers can be used by reflection  
caches that look up CLR helper methods. For example, Ruby’s  
ReflectionCache holds on MethodInfos for all RubyOps. Whenever a helper  
MethodInfo is needed a delegate is created for it and cached into  
CallInstruction’s cache along with the instruction that dispatches to  
it. Since all static helpers are known upfront the delegates and the  
corresponding instructions can all be ngen’d.

Moves helpers for rule interpretation from Ruby to DynamicUtils.

Python  
Replaces LazyDynamicExpressions with subclasses of  
LightDynamicExpressions.

Ruby  
Simplifies rules interpretation, moves related helpers to DLR.  
Uses LightDynamicExpression for all dynamic sites.  
Uses CallInstruction caching for RubyOps.

Tomas

---

<div class="post-metadata">

**Author:** ![grujildo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/94ad74/32.png) [@grujildo](https://www.ruby-forum.com/u/grujildo)\
**Post date:** [January 14, 2010, 1:01pm UTC](https://www.ruby-forum.com/t/code-review-lightbinding5/181521/2 "2010-01-14T13:01:27Z")

</div>

Tests look good.

JD

From: Dino Viehland  
Sent: Wednesday, January 13, 2010 10:46 AM  
To: Tomas M.; IronRuby External Code R.; Rowan Code  
Reviewers  
Cc: removed\_email\_address@domain.invalid  
Subject: RE: Code Review: LightBinding5

One nitpick: The usings in the namespace in DynamicUtils.cs are  
misformatted.

Otherwise looks great!

From: Tomas M.  
Sent: Tuesday, January 12, 2010 8:12 PM  
To: IronRuby External Code R.; Rowan Code R.  
Cc: removed\_email\_address@domain.invalid  
Subject: Code Review: LightBinding5

tfpt review “/shelveset:LightBinding5;REDMOND\tomat”

The changeset focuses on reducing time spent in JIT to compile generic  
instantiations of various helper methods. These are mostly related to  
generic instructions that implement dynamic sites and method calls. It  
reduces the number of methods jitted during startup time of irb from 481  
to 80 (with -X:CompilationThreshold 10000000), which translates to 34%  
time reduction:

rbr -X:CompilationThreshold 10000000 i.rb \< exit.txt

## i.rb:

## s = Time.now require ‘irb’ IRB.start( **FILE** ) t = Time.now p t - s

Before: 0.961096 seconds  
After: 0.631063 seconds

DLR

Adds LightDynamicExpression - these reducible nodes reduce to strongly  
typed DynamicExpressions yet when interpreted use untyped dynamic sites  
(sites typed to CallSite\<Func\<CallSite, object\*\>\>). Using light sites  
avoids jitting generic instantiations of various instructions, stubs and  
helpers that are strongly typed to the call-site signature. Also,  
strongly typed delegate types are created only when compiling the sites.

Adds helpers to CallInstruction that add MethodInfo to CallInstruction  
mapping into the internal cache. These helpers can be used by reflection  
caches that look up CLR helper methods. For example, Ruby’s  
ReflectionCache holds on MethodInfos for all RubyOps. Whenever a helper  
MethodInfo is needed a delegate is created for it and cached into  
CallInstruction’s cache along with the instruction that dispatches to  
it. Since all static helpers are known upfront the delegates and the  
corresponding instructions can all be ngen’d.

Moves helpers for rule interpretation from Ruby to DynamicUtils.

Python  
Replaces LazyDynamicExpressions with subclasses of  
LightDynamicExpressions.

Ruby  
Simplifies rules interpretation, moves related helpers to DLR.  
Uses LightDynamicExpression for all dynamic sites.  
Uses CallInstruction caching for RubyOps.

Tomas
