optimization - scala speed when using get() method on hash tables? (are temporary Option() objects generated?) -


i converting code scala. it's code sits in inner loop large amounts of data needs fast, , involves looking keys in hash table , computing probabilities. needs different things depending on whether key found or not. code using "standard" idiom:

counts.get(word) match {   case none => {     worddist.overall_word_probs.get(word) match {       case none => (unseen_mass*worddist.globally_unseen_word_prob                     / worddist.num_unseen_word_types)       case some(owprob) => unseen_mass * owprob / overall_unseen_mass     }   }   case some(wordcount) => wordcount.todouble/total_tokens*(1.0 - unseen_mass) } 

but concerned code of sort going slow because of these temporary some() objects being created , garbage-collected. scala2e book claims smart jvm "might" optimize these away code right thing efficiency-wise, happen using sun's jvm? know?

this may happen if enable escape analysis in jvm, enabled with:

-xx:+doescapeanalysis 

on jre 1.6. essentially, should detect objects being created not escape method activation frame , either allocate them on stack or gc them right after they're no longer needed.

one thing micro benchmark code using scala.testing.benchmark trait. extend singleton object , implement run method, compile , run it. run run method multiple times, , measure execution times.


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -