Feature #9196

Module#constants(false) should not use a hashtable internally

Added by Charlie Somerville over 1 year ago. Updated over 1 year ago.

[ruby-core:58786]
Status:Closed
Priority:Normal
Assignee:Charlie Somerville

Description

Module#constants always uses a hashtable to ensure that only unique constant names are returned - even when called with the inherit argument set to false.

Rails calls constants(false) heavily during boot and the use of a hashtable causes this method to show up as a hotspot (6% of boot time is spent in Module#constants).

Our app currently takes about 6.3 seconds to boot on trunk:

    6.33 real         5.20 user         1.10 sys
    6.27 real         5.17 user         1.07 sys
    6.27 real         5.17 user         1.07 sys
    6.35 real         5.25 user         1.07 sys
    6.29 real         5.18 user         1.08 sys

After applying the patch at https://github.com/charliesome/ruby/compare/optimized-constants-false, boot time drops to about 6 seconds:

    6.01 real         4.90 user         1.08 sys
    6.02 real         4.90 user         1.09 sys
    5.95 real         4.86 user         1.07 sys
    5.97 real         4.86 user         1.07 sys
    6.00 real         4.88 user         1.09 sys

Associated revisions

Revision 43956
Added by Charlie Somerville over 1 year ago

  • variable.c (rb_mod_constants): when calling Module#constants with inherit=false, there is no need to use a hashtable to deduplicate constant names. [Feature #9196]

Revision 43956
Added by Charlie Somerville over 1 year ago

  • variable.c (rb_mod_constants): when calling Module#constants with inherit=false, there is no need to use a hashtable to deduplicate constant names. [Feature #9196]

History

#1 Updated by Charlie Somerville over 1 year ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r43956.
Charlie, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • variable.c (rb_mod_constants): when calling Module#constants with inherit=false, there is no need to use a hashtable to deduplicate constant names. [Feature #9196]

Also available in: Atom PDF