Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@georgeglidden
Copy link
Contributor

Reworked the set_suffix_array_mem method of SufrFile (https://github.com/TravisWheelerLab/sufr/blob/main/libsufr/src/sufr_file.rs#L514C8-L514C28) to avoid redundant loading of the suffix array into memory:

  1. If the query's max_query_len is None, it defaults to self.text_len.to_usize(), which will be equal to built_max_query_len if the suffix array was also built with max_query_len set to None. This means that every time set_suffix_array_mem is called, the condition on line 539 is triggered, leading to the entire suffix array being read from disk. If multiple queries are made with the Options max_query_len: None, the suffix array will be read every single time.
  2. If the query len is different from the built query len, there is a condition for early-return if the loaded suffix array is nonempty and its internal max query len self.suffix_array_mem_mql matches the one from the Options. However, self.suffix_array_mem_mql is None by default and only gets set when the suffix array gets read from a non-cached file.
  3. Afaict, in every circumstance, by the end of set_suffix_array_mem, the suffix array in memory will have a max query len matching the Options max query len, so the change I made sets self.suffix_array_mem_mql = Some(max_query_len); whenever the function does not return early.
  4. To avoid the reloading issue in 1., I also moved the early-return in front of the other conditions, so that whenever a suffix array has been loaded into memory, and its max query length matches that of the Options' max query length, the method returns without doing redundant work.

@georgeglidden georgeglidden requested a review from kyclark March 26, 2025 23:27
@georgeglidden georgeglidden merged commit b4a924a into TravisWheelerLab:main Apr 3, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant