# Code Review: SingletonOptimizations

**URL:** <https://www.ruby-forum.com/t/code-review-singletonoptimizations/183348>\
**Category:** IronRuby\
**Created:** [February 12, 2010, 6:55am UTC](https://www.ruby-forum.com/t/code-review-singletonoptimizations/183348 "2010-02-12T06:55:08Z")\
**Posts on this page:** 1\
**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:** [February 12, 2010, 6:55am UTC](https://www.ruby-forum.com/t/code-review-singletonoptimizations/183348/1 "2010-02-12T06:55:08Z")

</div>

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

Optimizes allocation of singletons. Module singletons could be allocated  
lazily. We used to eagerly allocate a singleton for each allocated  
RubyModule. This is only necessary for classes. Their singletons are  
chained in the inheritance hierarchy parallel to the hierarchy of the  
classes. A module doesn’t have a super-class and thus we don’t need to  
create a singleton for it unless it has some members. Consequently 2  
modules of the same meta-module type with no singletons can share the  
same call-site rules. This sharing significantly improves RoR request  
time and reduces working set since the request processing code is using  
such modules.

Also fixes a few related minor bugs.

Previously:  
Initialized in 7.64449s  
10000 requests: 337 requests per second  
Peak working set: 216MB

Adaptively compiled:  
Initialized in 6.966271s  
10000 requests: 1132 requests per second  
Peak working set: 91MB

Compiled:  
Initialized in 26.106867s  
10000 requests: 1243 requests per second  
Peak working set: 89MB

MRI:  
Initialized in 2.82389s  
10000 requests: 1623 requests per second

Tomas
