Skip to content

AM::MassAssingmentSecurity: improve performance #5431

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
Mar 14, 2012

Conversation

bogdan
Copy link
Contributor

@bogdan bogdan commented Mar 14, 2012

According to this article:
http://merbist.com/2012/02/23/quick-dive-into-ruby-orm-object-initialization/

Current implementation of mass assignment security takes a lot of processor time because spawning to many redundant objects in MassAssignmentSecuritySanitizer#debug_protected_attribute_removal

We can get rid of this method.

Benchmark: https://gist.github.com/2036114

----------when something sanitized----------
New:   0.010000   0.000000   0.010000 (  0.006924)
Old:   0.010000   0.000000   0.010000 (  0.009284)
----------when nothing sanitized----------
New:   0.010000   0.000000   0.010000 (  0.003906)
Old:   0.000000   0.000000   0.000000 (  0.005500) 

A little side effect of this patch attributes are processed one by one. Instead of:

      def process_removed_attributes(attrs)

We get:

      def process_removed_attribute(attr)

The only one place where this could cause side effect is when someone wants to create it's own sanitizer(other than built-in Strict and Logger).

We can make a backward compatibility for this but decided that it doesn't make that much sense.

josevalim added a commit that referenced this pull request Mar 14, 2012
AM::MassAssingmentSecurity: improve performance
@josevalim josevalim merged commit cc1c4ac into rails:master Mar 14, 2012
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants