Improved ActiveSupport::Autoload performance.

`ActiveSupport::Autoload#autoload` performance is improved in the default
case where a path is present. Since the full path name is not generated, it
isn't necessary to determine the full constant name either. This results in a
3x performance gain and reduces the number of Ruby objects generated. For a full
benchmark check [this gist](https://gist.github.com/2020228).
This commit is contained in:
Pan Thomakos 2012-03-11 23:18:03 -07:00
parent 6c0d5a19a4
commit 6b480d2e82
1 changed files with 7 additions and 4 deletions

View File

@ -9,13 +9,16 @@ module ActiveSupport
@@eager_autoload = false @@eager_autoload = false
def autoload(const_name, path = @@at_path) def autoload(const_name, path = @@at_path)
full = [self.name, @@under_path, const_name.to_s, path].compact.join("::") unless path
location = path || Inflector.underscore(full) full = [name, @@under_path, const_name.to_s, path].compact.join("::")
path = Inflector.underscore(full)
end
if @@eager_autoload if @@eager_autoload
@@autoloads[const_name] = location @@autoloads[const_name] = path
end end
super const_name, location
super const_name, path
end end
def autoload_under(path) def autoload_under(path)