Skip to content
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

Hashie::Mash deep_merge is super O(2^n) slow #106

Closed
davemitchell opened this issue Jul 28, 2013 · 6 comments
Closed

Hashie::Mash deep_merge is super O(2^n) slow #106

davemitchell opened this issue Jul 28, 2013 · 6 comments

Comments

@davemitchell
Copy link
Contributor

Mash's deep_merge is recursively invoked 2^n times, where n is the depth of the other_hash parameter. For instance,

 x = Hashie::Mash.new()
 x.a!.b!.c!.d!.e!.f!.g!.h!.i!.j!.k!.l!.m!.n!.o!.p!.q!.r!.s!.t = 0
 y = Hashie::Mash.new(x)

...will call deep_merge over a million times (2^20), taking 10-15 seconds to complete.

I've made an a O(n) fix in which deep_merge is only invoked 20 times for the above example, with sub-millisecond response. Will submit a pull request momentarily.

davemitchell added a commit to connectedbits/hashie that referenced this issue Jul 28, 2013
The call to custom_writer within deep_merge was exponentially converting the values (unnecessarily, since they were just converted within deep_merge).  Added an optional param to custom_writer to suppress the conversion.  Unfortunately, had to also add the param to coercion's customer_writer method as well (which is just ignored) to not break the inheritance.

All tests pass.
@masatomo
Copy link

masatomo commented Sep 2, 2013

This issue is actually critical. Without this patch, a request with just 10 elements of array takes more than 30 seconds.

I strongly recommend to merge this patch and release new version of Hashie asap. We are using the @davemitchell's forked repo until this is merged. (thank you so much for this patch, @davemitchell !)

@johnae
Copy link

johnae commented Sep 10, 2013

Yeah I second that. Just did a bundle update on another gem and along came Hashie 2.0.5 - specs became 10x slower all because of Hashie. Took me two hours to understand what happened.

@johnae
Copy link

johnae commented Oct 8, 2013

@jch @wapcaplet @markiz @craiglittle @7even @jimeh @davemitchell hey guys this issue is a big one really, this pull request shouldn't just be sitting here for months. 2.0.5 is unusable in it's current state.

@jch
Copy link
Contributor

jch commented Oct 8, 2013

Sorry, I was helping, but I lost access after leaving Intridea. The project
doesn't seem actively maintained, perhaps it's time to find a new
maintainer?

On Tuesday, October 8, 2013, John Axel Eriksson wrote:

@jch https://github.com/jch @wapcaplet https://github.com/wapcaplet
@markiz https://github.com/markiz @craiglittlehttps://github.com/craiglittle
@7even https://github.com/7even @jimeh https://github.com/jimeh
@davemitchell https://github.com/davemitchell hey guys this issue is a
big one really, this pull request shouldn't just be sitting here for
months. 2.0.5 is unusable in it's current state.


Reply to this email directly or view it on GitHubhttps://github.com//issues/106#issuecomment-25883756
.

-Jerry
@whatcodecraves http://twitter.com/whatcodecraves
github http://github.com/jch

@dblock
Copy link
Member

dblock commented Mar 30, 2014

I am taking over. The fix has now been merged on master and I will make a release this week after I've gone through all the pending PRs.

@dblock dblock closed this as completed Mar 30, 2014
@davemitchell
Copy link
Contributor Author

sweet!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants