-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
optimize XML serialization #55
base: master
Are you sure you want to change the base?
Conversation
@ThomasSevestre this looks amazing but I believe extending core classes in a "leaf" library is not a great idea. Can we achieve the same with a module in the gem that would contain all those helper methods, without core namespace alterations? |
I’m against patching core classes, too. I’m also curious as to why this is faster than the existing code. Would you care to explain? |
I do not like patching core classes as well... I'm not sure it is possible to achieve the same performance in a different way. In current code, the expensive part is the big case when : case value
when Numeric
when TrueClass, FalseClass
when Time
when DateTime
when Date
else
end It is using This trick is also used by rails teams, here for instance : rails/rails@d36eb239 |
The Rails team is at liberty adding methods to core classes, but this is not the liberty authors of "leaf" libraries have - just due to the adoption. |
Yes. I'm not trying to advocate for core class patches, just explaining the performance gain. It may be acceptable to load this optimisation explicitly ? Like this for instance : require "xlsxstream"
require "xlsxstream/core_extension" |
Another solution would be to optimize for It would look like this : case value
when nil
# noop
when String
when Numeric
when TrueClass, FalseClass
when Time
when DateTime
when Date
else
# recursive call to handle value.to_s
end It will ensure good performance for common types. What do you think ? |
@ThomasSevestre I like the idea with the optimized case statement. Could you benchmark that version? |
This PR improves performance of XML serialization :
This has a visible impact in our application using ActiveRecord. I have a 15% overall gain.
I'm using this script to benchmark :