Skip to content

Commit

Permalink
Add some debugging to report hashmap sizes.
Browse files Browse the repository at this point in the history
Tweak hashsizes sizes for rules.
  • Loading branch information
NSoiffer committed Jan 5, 2025
1 parent 9a5ba5c commit 47b034e
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 17 deletions.
38 changes: 26 additions & 12 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,19 @@ fn main() {
// </math>";

let expr = r#"
<math display='block'>
<mn>1.5</mn><mi intent=':unit'>km</mi>
<mn>2</mn><mi intent=':unit' mathvariant='normal'>Ω</mi>
<mn>1</mn><mi id='ohm-id' mathvariant='normal'>Ω</mi>
<mo>+</mo>
<mn>3</mn><mi intent=':unit' mathvariant='normal'>ft</mi>
</math>
"#;
<math data-latex='\vec{A} \perp \vec{B}' display='block'>
<mrow data-changed='added'>
<mover data-latex='\vec{A}' data-mjx-texclass='ORD'>
<mi data-latex='A'>A</mi>
<mo stretchy='false'>→</mo>
</mover>
<mo data-latex='\perp'>⊥</mo>
<mover data-latex='\vec{B}' data-mjx-texclass='ORD'>
<mi data-latex='B'>B</mi>
<mo stretchy='false'>→</mo>
</mover>
</mrow>
</math>"#;
// let expr= "<math><mrow><mi>sin</mi><mo>(</mo><mi>x</mi><mo>)</mo><mo>+</mo><mi>f</mi><mo>(</mo><mi>x</mi><mo>)</mo></mrow></math>";
let instant = Instant::now();
let rules_dir = std::env::current_exe().unwrap().parent().unwrap().join("../../Rules");
Expand All @@ -195,7 +200,7 @@ fn main() {
set_preference("DecimalSeparator".to_string(), "Auto".to_string()).unwrap();
set_preference("BrailleCode".to_string(), "UEB".to_string()).unwrap();
set_preference("TTS".to_string(), "None".to_string()).unwrap();
set_preference("Verbosity".to_string(), "Medium,".to_string()).unwrap();
set_preference("Verbosity".to_string(), "Verbose,".to_string()).unwrap();
set_preference("Impairment".to_string(), "Blindness".to_string()).unwrap();
set_preference("SpeechOverrides_CapitalLetters".to_string(), "".to_string()).unwrap();
set_preference("MathRate".to_string(), "80".to_string()).unwrap();
Expand All @@ -207,16 +212,25 @@ fn main() {

set_preference("Bookmark".to_string(), "false".to_string()).unwrap();
set_preference("SpeechStyle".to_string(), "SimpleSpeak".to_string()).unwrap();
// set_preference("DecimalSeparators".to_string(), ", ".to_string()).unwrap();
// set_preference("BlockSeparators".to_string(), ".".to_string()).unwrap();
// set_preference("DecimalSeparators".to_string(), ",".to_string()).unwrap();
// set_preference("BlockSeparators".to_string(), ". ".to_string()).unwrap();
if let Err(e) = set_mathml(expr.to_string()) {
panic!("Error: exiting -- {}", errors_to_string(&e));
};

// match do_navigate_command("MoveStart".to_string()) {
// Err(e) => panic!("Error: exiting -- {}", errors_to_string(&e)),
// Ok(speech) => info!("MoveStart speech: '{}'", speech),
// }
// match do_navigate_command("MoveNext".to_string()) {
// Err(e) => panic!("Error: exiting -- {}", errors_to_string(&e)),
// Ok(speech) => info!("MoveNext speech: '{}'", speech),
// }
match get_spoken_text() {
Ok(speech) => info!("Computed speech string:\n '{}'", speech),
Err(e) => panic!("{}", errors_to_string(&e)),
}
debug!("Speech language is {}", get_preference("Language".to_string()).unwrap());
debug!("DecimalSeparator: {:?}", get_preference("DecimalSeparator".to_string()).unwrap());
debug!("DecimalSeparators: {:?}, BlockSeparators: {:?}", get_preference("DecimalSeparators".to_string()).unwrap(), get_preference("BlockSeparators".to_string()).unwrap());
info!("SpeechStyle: {:?}", get_preference("SpeechStyle".to_string()).unwrap());
Expand All @@ -239,7 +253,7 @@ fn main() {
// let xpath_counts = libmathcat::speech::xpath_count();
// info!("#xpath = {}; duplicates = {}", xpath_counts.0, xpath_counts.1);
info!("Time taken (second time for speech + braille): {}ms", instant.elapsed().as_millis());

// debug!("Hashmap sizes:\n{}", libmathcat::speech::SpeechRules::print_sizes());
timing_test(expr, 0);

}
Expand Down
43 changes: 38 additions & 5 deletions src/speech.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2058,19 +2058,19 @@ impl<'c, 's:'c, 'm:'c> fmt::Display for SpeechRulesWithContext<'c, 's,'m> {
thread_local!{
/// SPEECH_UNICODE_SHORT is shared among several rules, so "RC" is used
static SPEECH_UNICODE_SHORT: UnicodeTable =
Rc::new( RefCell::new( HashMap::with_capacity(497) ) );
Rc::new( RefCell::new( HashMap::with_capacity(500) ) );

/// SPEECH_UNICODE_FULL is shared among several rules, so "RC" is used
static SPEECH_UNICODE_FULL: UnicodeTable =
Rc::new( RefCell::new( HashMap::with_capacity(6997) ) );
Rc::new( RefCell::new( HashMap::with_capacity(6500) ) );

/// BRAILLE_UNICODE_SHORT is shared among several rules, so "RC" is used
static BRAILLE_UNICODE_SHORT: UnicodeTable =
Rc::new( RefCell::new( HashMap::with_capacity(497) ) );
Rc::new( RefCell::new( HashMap::with_capacity(500) ) );

/// BRAILLE_UNICODE_FULL is shared among several rules, so "RC" is used
static BRAILLE_UNICODE_FULL: UnicodeTable =
Rc::new( RefCell::new( HashMap::with_capacity(6997) ) );
Rc::new( RefCell::new( HashMap::with_capacity(5000) ) );

/// SPEECH_DEFINITION_FILES_AND_TIMES is shared among several rules, so "RC" is used
static SPEECH_DEFINITION_FILES_AND_TIMES: FilesAndTimesShared =
Expand Down Expand Up @@ -2133,7 +2133,7 @@ impl SpeechRules {
return SpeechRules {
error: Default::default(),
name,
rules: HashMap::with_capacity(if name == RulesFor::Intent {1023} else {31}), // lazy load them
rules: HashMap::with_capacity(if name == RulesFor::Intent || name == RulesFor::Speech {500} else {50}), // lazy load them
rule_files: FilesAndTimes::default(),
unicode_short: globals.0.0, // lazy load them
unicode_short_files: globals.0.1,
Expand Down Expand Up @@ -2247,6 +2247,39 @@ impl SpeechRules {
return compile_rule(&unicode_file_contents, unicode_build_fn)
.chain_err(||format!("in file {:?}", path.to_str().unwrap()));
}

pub fn print_sizes() -> String {
// let _ = &SPEECH_RULES.with_borrow(|rules| {
// debug!("SPEECH RULES entries\n");
// let rules = &rules.rules;
// for (key, _) in rules.iter() {
// debug!("key: {}", key);
// }
// });
let mut answer = rule_size(&SPEECH_RULES, "SPEECH_RULES");
answer += &rule_size(&INTENT_RULES, "INTENT_RULES");
answer += &rule_size(&BRAILLE_RULES, "BRAILLE_RULES");
answer += &rule_size(&NAVIGATION_RULES, "NAVIGATION_RULES");
answer += &rule_size(&OVERVIEW_RULES, "OVERVIEW_RULES");
SPEECH_RULES.with_borrow(|rule| {
answer += &format!("Speech Unicode tables: short={}/{}, long={}/{}\n",
rule.unicode_short.borrow().len(), rule.unicode_short.borrow().capacity(),
rule.unicode_full.borrow().len(), rule.unicode_full.borrow().capacity());
});
BRAILLE_RULES.with_borrow(|rule| {
answer += &format!("Braille Unicode tables: short={}/{}, long={}/{}\n",
rule.unicode_short.borrow().len(), rule.unicode_short.borrow().capacity(),
rule.unicode_full.borrow().len(), rule.unicode_full.borrow().capacity());
});
return answer;

fn rule_size(rules: &'static std::thread::LocalKey<RefCell<SpeechRules>>, name: &str) -> String {
rules.with_borrow(|rule| {
let hash_map = &rule.rules;
return format!("{}: {}/{}\n", name, hash_map.len(), hash_map.capacity());
})
}
}
}


Expand Down

0 comments on commit 47b034e

Please sign in to comment.