When JIT Compiler compiles the append_features in the 
ruby\site_ruby\1.8\builtin\javasupport\proxy\interface.rb the compiled code 
slows down by a factor of 10
--------------------------------------------------------------------------------------------------------------------------------------------------------------

                 Key: JRUBY-2680
                 URL: http://jira.codehaus.org/browse/JRUBY-2680
             Project: JRuby
          Issue Type: Bug
    Affects Versions: JRuby 1.1.2, JRuby 1.1.1
         Environment: Sun Solaris Sparc, Windows XP Intel
            Reporter: Chase Wolfinger
            Assignee: Thomas E Enebo


When executing the following code to access the JAXP xpath parser the code is 
10x slower then with if the append_feature is not JITed.  In this case we are 
pooling Xpath objects - but the problem exists on any other objects.


This code is 10x slower when it is Jitted - specifically the append_feature 
that is JITed -->

{{def xsd_element expr, doc
        xpath_pool = OAM::XPathPool.instance
        xpath = xpath_pool.borrow_xpath
        xpath.set_namespace_context(NamespaceContext.new(doc.prefix, 
doc.namespace_uri))
        nodes = xpath.evaluate(expr, doc, 
javax.xml.xpath.XPathConstants.const_get('NODESET'))
        elems = (0...nodes.length).collect do |i|
          nodes.item(i)
        end
        xpath_pool.return_xpath(xpath)
        elems
      end
}}
This is the module used in this method - note this requires Apache commons jar:
{{
module OAM
  class DocumentBuilderFact
    private_class_method :new    
    def self.instance
      @@instance ||= create_new_instance
    end
    
    private
    def self.create_new_instance
      doc_builder_factory = 
javax.xml.parsers.DocumentBuilderFactory.new_instance
      doc_builder_factory.set_namespace_aware(true)
      doc_builder_factory
    end
  end
  
  class XPathFact
    private_class_method :new    
    def self.instance
      @@instance ||= javax.xml.xpath.XPathFactory.new_instance
    end
  end
  
  class DocBuilderPool    
    include Singleton
    
    def initialize
      self.doc_builder_pool = ObjectPool.new(DocBuilderFactory.new)
    end
    
    def borrow_doc_builder
      self.doc_builder_pool.borrow_object
    end
    
    def return_doc_builder(doc_builder)
      self.doc_builder_pool.return_object(doc_builder)
    end
    
    private
    attr_accessor :doc_builder_pool
    
    class DocBuilderFactory < BasePoolableObjectFactory
      def make_object
        DocumentBuilderFact.instance.new_document_builder
      end
      alias_method :makeObject, :make_object
    end
  end
  
  class ObjectPool         
    def initialize(factory)
      self.object_pool = GenericObjectPool.new
      self.object_pool.set_factory(factory)
      self.object_pool.set_max_active(-1)
      self.object_pool.set_max_idle(-1)
      
self.object_pool.set_when_exhausted_action(GenericObjectPool.const_get("WHEN_EXHAUSTED_GROW"))
    end
    
    def borrow_object
      self.object_pool.borrow_object
    end
    
    def return_object(object)
      self.object_pool.return_object(object)
    end
    
    private
    attr_accessor :object_pool    
  end
  
  class XPathPool
    include Singleton
    
    def initialize
      self.xpath_pool = ObjectPool.new(XPathFactory.new)
    end
    
    def borrow_xpath
      self.xpath_pool.borrow_object
    end
    
    def return_xpath(xpath)
      self.xpath_pool.return_object(xpath)
    end
    
    private
    attr_accessor :xpath_pool
    
    class XPathFactory < BasePoolableObjectFactory
      def make_object
        XPathFact.instance.new_xpath
      end
      alias_method :makeObject, :make_object
    end
  end
}}


-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to