Bad performance using hash accessors on ConcurrentMap -----------------------------------------------------
Key: JRUBY-5994 URL: https://jira.codehaus.org/browse/JRUBY-5994 Project: JRuby Issue Type: Bug Components: Java Integration Affects Versions: JRuby 1.6.3 Environment: Mac OS 10.7 java version "1.6.0_26" Java(TM) SE Runtime Environment (build 1.6.0_26-b03-383-11A511) Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02-383, mixed mode) Reporter: Martin Kleppmann Priority: Minor Google's Guava libraries (http://code.google.com/p/guava-libraries/) contain some useful collection classes, which I'm using from JRuby. One that I'm using is an implementation of java.util.concurrent.ConcurrentMap, and JRuby kindly allows you to access it like a normal Ruby hash. It seems to work correctly, but unfortunately it's _incredibly_ slow. In the example below, the difference in runtime between two functionally equivalent lines of code is more than 2 orders of magnitude. {noformat} > require 'java' > require 'guava-r09.jar' > require 'benchmark' > map = > com.google.common.collect.MapMaker.new.maximum_size(200_000).concurrency_level(1).make_map => {} > puts Benchmark.measure{ (1..4000).each{|n| map.put("hello #{n}", 42) unless > map.contains_key("hello #{n}") } } 0.041000 0.000000 0.041000 ( 0.041000) => nil > map = > com.google.common.collect.MapMaker.new.maximum_size(2000).concurrency_level(1).make_map => {} > puts Benchmark.measure{ (1..4000).each{|n| map["hello #{n}"] ||= 42 } } 8.461000 0.000000 8.461000 ( 8.461000) => nil {noformat} -- This message is automatically generated by JIRA. 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