[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, upstream, updated. 0.25.5-663-g71824ee

Markus Roberts Markus at reality.com
Tue Jul 20 07:42:25 UTC 2010


The following commit has been merged in the upstream branch:
commit dd03ac9fa29fce36eb64a5f831be8757f2f96f5c
Author: Markus Roberts <Markus at reality.com>
Date:   Sun Jul 18 13:25:43 2010 -0700

    Partial fix for #4278 -- the performance aspects
    
    unevaluated_resources was a performance bottleneck and was doing a great deal
    of unneeded work, such as searching for the type of evaluated resources before
    ignoring them because only unevaluated resources were wanted.
    
    This patch is behaviour neutral but gives a 2-3x speedup for compiles with many
    defined resources.

diff --git a/lib/puppet/parser/compiler.rb b/lib/puppet/parser/compiler.rb
index 8598072..a901c0d 100644
--- a/lib/puppet/parser/compiler.rb
+++ b/lib/puppet/parser/compiler.rb
@@ -251,19 +251,7 @@ class Puppet::Parser::Compiler
   # evaluate_generators loop.
   def evaluate_definitions
     exceptwrap do
-      if ary = unevaluated_resources
-        evaluated = false
-        ary.each do |resource|
-          if not resource.virtual?
-            resource.evaluate
-            evaluated = true
-          end
-        end
-        # If we evaluated, let the loop know.
-        return evaluated
-      else
-        return false
-      end
+      !unevaluated_resources.each { |resource| resource.evaluate }.empty?
     end
   end
 
@@ -482,12 +470,7 @@ class Puppet::Parser::Compiler
   # Return an array of all of the unevaluated resources.  These will be definitions,
   # which need to get evaluated into native resources.
   def unevaluated_resources
-    ary = resources.reject { |resource| resource.builtin? or resource.evaluated?  }
-
-    if ary.empty?
-      return nil
-    else
-      return ary
-    end
+    # The order of these is significant for speed due to short-circuting
+    resources.reject { |resource| resource.evaluated? or resource.virtual? or resource.builtin_type? }
   end
 end
diff --git a/lib/puppet/parser/resource.rb b/lib/puppet/parser/resource.rb
index 3cccf4f..c956a11 100644
--- a/lib/puppet/parser/resource.rb
+++ b/lib/puppet/parser/resource.rb
@@ -32,12 +32,9 @@ class Puppet::Parser::Resource < Puppet::Resource
   end
 
   # Set up some boolean test methods
-  [:translated, :override, :evaluated].each do |method|
-    newmeth = (method.to_s + "?").intern
-    define_method(newmeth) do
-      self.send(method)
-    end
-  end
+  def translated?; !!@translated; end
+  def override?;   !!@override;   end
+  def evaluated?;  !!@evaluated;  end
 
   def [](param)
     param = symbolize(param)
diff --git a/lib/puppet/resource.rb b/lib/puppet/resource.rb
index 31237e3..d163d93 100644
--- a/lib/puppet/resource.rb
+++ b/lib/puppet/resource.rb
@@ -199,7 +199,7 @@ class Puppet::Resource
   end
 
   def resource_type
-    case type
+    @resource_type ||= case type
     when "Class"; find_hostclass(title)
     when "Node"; find_node(title)
     else
diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb
index d0fea97..5676b5d 100644
--- a/lib/puppet/type.rb
+++ b/lib/puppet/type.rb
@@ -1874,12 +1874,8 @@ class Type
     self.to_trans.to_resource
   end
 
-  %w{exported virtual}.each do |m|
-    define_method(m+"?") do
-      self.send(m)
-    end
-  end
-
+  def virtual?;  !!@virtual;  end
+  def exported?; !!@exported; end
 end
 end
 
diff --git a/spec/unit/parser/compiler_spec.rb b/spec/unit/parser/compiler_spec.rb
index a3fe56c..e8c06dd 100755
--- a/spec/unit/parser/compiler_spec.rb
+++ b/spec/unit/parser/compiler_spec.rb
@@ -23,7 +23,7 @@ class CompilerTestResource
     @evaluated
   end
 
-  def builtin?
+  def builtin_type?
     @builtin
   end
 

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list