aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib/active_model/naming.rb
Commit message (Collapse)AuthorAgeFilesLines
* Fixed humane -> human [ci skip]Pratik2015-09-261-1/+1
|
* Freeze string literals when not mutated.schneems2015-07-191-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I wrote a utility that helps find areas where you could optimize your program using a frozen string instead of a string literal, it's called [let_it_go](https://github.com/schneems/let_it_go). After going through the output and adding `.freeze` I was able to eliminate the creation of 1,114 string objects on EVERY request to [codetriage](codetriage.com). How does this impact execution? To look at memory: ```ruby require 'get_process_mem' mem = GetProcessMem.new GC.start GC.disable 1_114.times { " " } before = mem.mb after = mem.mb GC.enable puts "Diff: #{after - before} mb" ``` Creating 1,114 string objects results in `Diff: 0.03125 mb` of RAM allocated on every request. Or 1mb every 32 requests. To look at raw speed: ```ruby require 'benchmark/ips' number_of_objects_reduced = 1_114 Benchmark.ips do |x| x.report("freeze") { number_of_objects_reduced.times { " ".freeze } } x.report("no-freeze") { number_of_objects_reduced.times { " " } } end ``` We get the results ``` Calculating ------------------------------------- freeze 1.428k i/100ms no-freeze 609.000 i/100ms ------------------------------------------------- freeze 14.363k (± 8.5%) i/s - 71.400k no-freeze 6.084k (± 8.1%) i/s - 30.450k ``` Now we can do some maths: ```ruby ips = 6_226k # iterations / 1 second call_time_before = 1.0 / ips # seconds per iteration ips = 15_254 # iterations / 1 second call_time_after = 1.0 / ips # seconds per iteration diff = call_time_before - call_time_after number_of_objects_reduced * diff * 100 # => 0.4530373333993266 miliseconds saved per request ``` So we're shaving off 1 second of execution time for every 220 requests. Is this going to be an insane speed boost to any Rails app: nope. Should we merge it: yep. p.s. If you know of a method call that doesn't modify a string input such as [String#gsub](https://github.com/schneems/let_it_go/blob/b0e2da69f0cca87ab581022baa43291cdf48638c/lib/let_it_go/core_ext/string.rb#L37) please [give me a pull request to the appropriate file](https://github.com/schneems/let_it_go/blob/b0e2da69f0cca87ab581022baa43291cdf48638c/lib/let_it_go/core_ext/string.rb#L37), or open an issue in LetItGo so we can track and freeze more strings. Keep those strings Frozen ![](https://www.dropbox.com/s/z4dj9fdsv213r4v/let-it-go.gif?dl=1)
* Require Module#delegate core ext in ActiveModel::NamingRyan Bigg2015-03-311-0/+1
|
* activemodel: make .model_name json encodableIan Ker-Seymer2015-02-241-1/+1
| | | | | | Previously, calling `User.model_name.to_json` would result in an infinite recursion as `.model_name` inherited its `.as_json` behavior from Object. This patch fixes that unexpected behavior by delegating `.as_json` to :name.
* Add missing AS core extension dependencyWojciech Wnętrzak2015-01-211-0/+1
|
* removing unecessary parameter in private methodGeorge Millo2015-01-061-2/+2
| | | | '_singularize' only ever gets called with one argument
* Use Active Model, not ActiveModel in plain Englishclaudiob2015-01-021-1/+1
| | | | | | | Also prevents the word "Model" from linking to the documentation of ActiveModel::Model because that's not intended. [ci skip]
* No need to check model_name anymoreRafael Mendonça França2014-08-171-4/+2
|
* Merge pull request #15889 from carnesmedia/model-nameRafael Mendonça França2014-08-171-1/+1
|\ | | | | | | Use #model_name on instances instead of classes
| * Use #model_name on instances instead of classesAmiel Martin2014-06-241-1/+1
| | | | | | | | | | | | This allows rails code to be more confdent when asking for a model name, instead of having to ask for the class. Rails core discussion here: https://groups.google.com/forum/#!topic/rubyonrails-core/ThSaXw9y1F8
* | Call public methods rather than class_eval'ingCarlos Antonio da Silva2014-08-051-4/+2
| |
* | Silence warning emitted in testsSean Griffin2014-07-011-0/+1
|/ | | | | The instance method `model_name` was being defined multiple times, causing a redefinition warning.
* Delegate #model_name method to self.classYuki Nishijima2014-06-221-0/+6
|
* [ci skip] Include ActiveModel::Model in a class instead of inheritingAkshay Vishnoi2014-05-301-2/+3
|
* Name#model_name doesn't return a String objectShunsukeAida2014-05-301-1/+1
|
* Change syntax format for example returned valuesPrem Sichanugrist2013-11-111-6/+6
| | | | | | | | | According to our guideline, we leave 1 space between `#` and `=>`, so we want `# =>` instead of `#=>`. Thanks to @fxn for the suggestion. [ci skip]
* Merge pull request #12686 from kryzhovnik/masterCarlos Antonio da Silva2013-11-021-6/+6
|\ | | | | | | | | | | | | Minor doc fix of ActiveModel::Naming. [ci skip] Conflicts: activemodel/lib/active_model/naming.rb
| * Minor doc fix of ActiveModel::Naming.Andrey Samsonov2013-10-291-6/+6
| | | | | | | | | | - qoute example line's result when it kind of String - right ("singular_route_key") method in example
* | Revert "Merge pull request #11053 from yangchenyun/mine"José Valim2013-06-221-2/+0
| | | | | | | | | | | | | | | | | | | | | | Those two files are required by active_support/rails.rb loaded in active_model.rb It is common to require common dependencies on the root files to avoid boilerplate in each file. This reverts commit 763635e30f17800ebc0a8ae98d780edc8ebfb4e5, reversing changes made to 4f46ef36aaef217834f3f96d3689d32f6a6761ea.
* | add explicit AS dependencies for ActiveModel::NamingSteven Yang2013-06-221-0/+2
| | | | | | | | | | | | | | | | There are two missing ActiveSupport dependencies to use ActiveModel::Name class or ActiveModel::Naming module independently. Missing dependencies for Module#delegate defined in `active_support/core_ext/module/delegation`, used at [L148](https://github.com/rails/rails/blob/master/activemodel/lib/active_model/naming.rb#L148) Missing dependencies for Object#blank? defined in `active_support/core_ext/object/blank`, used at [L131](https://github.com/rails/rails/blob/master/activemodel/lib/active_model/naming.rb#L131)
* | Convert ActiveModel to 1.9 hash syntax.Patrick Robertson2013-05-011-2/+2
| | | | | | | | | | I also attempted to fix other styleguide violations such as { a: :b } over {a: :b} and foo(b: 'bar') over foo( b: 'bar' ).
* | cleanup, removed dispensable `require` statements from `ActiveModel`Yves Senn2012-11-251-1/+0
| |
* | cleanup, remove broken whitespaceYves Senn2012-11-251-2/+2
| |
* | Trivial documentation fix for ActiveModel::Naming comment.Dennis Taylor2012-11-091-2/+2
| |
* | minor edits in AM documentation [ci skip]Francesco Rodriguez2012-10-211-1/+1
|/
* Refactor model name logic and make it a real private class methodCarlos Antonio da Silva2012-08-111-5/+8
| | | | | | | Under a "private" call, class methods are not real private methods, they're public just like any other method. Make model_name_from_record_or_class a private class method, and nodoc it.
* Naming helpers should first check if passed object responds to model_nameBert Goethals2012-08-081-5/+3
|
* Merge branch 'master' of github.com:lifo/docrailsVijay Dev2012-08-041-12/+20
|\ | | | | | | | | | | Conflicts: activemodel/lib/active_model/secure_password.rb activerecord/lib/active_record/associations/collection_proxy.rb
| * add example to ActiveModel::Naming#model_name [ci skip]Francesco Rodriguez2012-07-271-0/+8
| |
| * fix AM::Naming examples [ci skip]Francesco Rodriguez2012-07-271-12/+12
| |
* | load active_support/core_ext/module/delegation in active_support/railsXavier Noria2012-08-021-1/+0
| |
* | load active_support/core_ext/object/blank in active_support/railsXavier Noria2012-08-021-1/+0
|/
* update ActiveModel::Name documentation [ci skip]Francesco Rodriguez2012-06-251-1/+133
|
* update ActiveModel::Naming documentationFrancesco Rodriguez2012-06-231-7/+8
|
* Refactor human attribute nameCarlos Antonio da Silva2012-04-281-1/+1
|
* Don't include deprecation in AM::Naming anymoreGrant Hutchins2012-03-311-1/+0
|
* no need to freeze things all the timeAaron Patterson2012-03-261-8/+7
|
* ActiveModel::Name does not inherit from stringLukasz Sarnacki2012-03-261-11/+16
|
* Remove ActiveModel::Naming#partial_pathGrant Hutchins2012-03-101-4/+1
| | | It was deprecated in 3.2
* Added missing ActiveModel::Naming dependency.Shane Hanna2012-03-091-0/+1
| | | | | ActiveModel::Name constructor expects to be able to call #blank? on a String but the core Object#blank? extension is never required.
* Improve cache on route_key lookup.José Valim2011-12-081-2/+23
|
* ActiveModel::Name#i18n_key: Fix doc and add testsMarc-Andre Lafortune2011-12-051-2/+2
|
* make ActiveModel::Name fail gracefully with anonymous classesJakub Kuźma2011-11-241-0/+3
|
* Rely on a public contract between railties instead of accessing railtie ↵José Valim2011-11-231-11/+13
| | | | methods directly.
* Rename new method to_path to to_partial_path to avoid conflicts with ↵José Valim2011-08-011-1/+1
| | | | File#to_path and similar.
* Let ActiveModel instances define partial paths.Grant Hutchins & Peter Jaros2011-07-251-0/+3
| | | | | | Deprecate ActiveModel::Name#partial_path. Now you should call #to_path directly on ActiveModel instances.
* Get rid of the alternate namespace lookup.José Valim2011-06-111-4/+3
|
* Brought back alternative convention for namespaced models in i18n.thoefer2011-06-081-3/+4
|
* Specify the name to be used for ActiveModel::Name fixes #1168Yves Senn2011-05-201-2/+3
| | | | This patch allows to specify the name of your models independent of the class name.
* Removed extra whitespaceSebastian Martinez2011-04-261-1/+1
|