Issue #17820 has been updated by Josh Cooper.

Per and Linus, I was able to reproduce this pretty easily. Given:

<pre>
Resource = Struct.new(:name)
made = []
(1..10000).each do |i|
  made << Resource.new(i.to_s)
end
</pre>

I get the following results:

<table>
<tr><th>call</th><th>time</th></tr>
<tr><td>made.inject({}) {|a,v| a.merge(v.name => v) 
}</td><td>0m15.891s</td></tr>
<tr><td>made.inject({}) {|a,v| a[v.name] = v; a}</td><td>0m0.033s</td></tr>
<tr><td>Hash[made.map(&:name).zip(made)]</td><td>0m0.031s</td></tr>
</table>

The first version is what's in 2.7.9 and up. The second version is your patch, 
and is compatible with ruby 1.8.5. I'll submit a pull request with this change 
to 2.7.x. The third version is the original code as was implemented in 7002eff. 
This is the fastest version, but is not compatible with ruby 1.8.5. Since 
Puppet 3 is not compatible with 1.8.5, I'll issue a separate pull request for 
3.0.x.

Thanks again for finding this issue!
----------------------------------------
Bug #17820: eval_generate is needlessly slow
https://projects.puppetlabs.com/issues/17820#change-77547

Author: Per Cederqvist
Status: Accepted
Priority: Normal
Assignee: 
Category: performance
Target version: 
Affected Puppet version: 2.7.9
Keywords: 
Branch: 


By changing a single line in eval_generate in lib/puppet/transaction.rb I 
managed to speed up "puppet agent --test" from 4494 to 593 seconds. The code 
should produce the same result, but avoids allocating so many hashes.

Here is the diff.  If you prefer, I can create a Git branch et c, but I hope it 
isn't necessary for such a simple fix.

I'm also attaching the output from two ruby-prof runs, in call graph format: 
before and after the change.

(593 seconds is still too much. I suspect I might be submitting a new bug 
report in the not too distant future. :-)  Still, this change should be a 
speedup for everybody, and it shouldn't hurt anybody.)


-- 
You have received this notification because you have either subscribed to it, 
or are involved in it.
To change your notification preferences, please click here: 
http://projects.puppetlabs.com/my/account

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Bugs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-bugs?hl=en.

Reply via email to