Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] [Tech Debt] BFS is slower than we'd like #108

Open
bee-san opened this issue Nov 29, 2022 · 0 comments
Open

[BUG] [Tech Debt] BFS is slower than we'd like #108

bee-san opened this issue Nov 29, 2022 · 0 comments
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed Technical Debt A conscious decision we have made to reach our goals faster which has resulted in technical debt

Comments

@bee-san
Copy link
Owner

bee-san commented Nov 29, 2022

#107

Every Text struct contains a field:

text: Vec<String>,

Which contains every decoding (even if it's just 1 decoding).

After each iteration of BFS we loop over all of our vectors we have collected and flatten them from a Vec<Vec<Text>> to a Vec<Text> where text: Vec<String> has a single element (meaning we can index into the 0th element [0] and get the result).

        let mut new_strings_to_be_added = Vec::new();
        for textStruct in new_strings{
            for decoded_text in textStruct.text{
                new_strings_to_be_added.push(
                    Text {
                        text: vec![decoded_text],
                        // quick hack
                        path: textStruct.path.clone(),
                    }
                )
            }

This introduces some issues:

  1. It is not efficient to have a O(n^2) loop after our big main loop
  2. We are using .clone() here which is slow
  3. It is not efficient to make a new vector with just 1 element
  4. It does not support nice paths. If it was Caesar, it won't say "Caesar with shift of 13" for example

This is a hack to get us to support this feature.

In the future we might want to look at:

Editing this bit of code so it supports Vectors of Vectors:
https://github.com/bee-san/Ares/blob/1bcc994052db17e7db948055d012810353c76f4d/src/searchers/bfs.rs#LL32-L33C69

Or adding another loop below this code so it turns into a O(n^2) nested loop:

while !current_strings.is_empty() {

@bee-san bee-san added bug Something isn't working help wanted Extra attention is needed good first issue Good for newcomers Technical Debt A conscious decision we have made to reach our goals faster which has resulted in technical debt labels Nov 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed Technical Debt A conscious decision we have made to reach our goals faster which has resulted in technical debt
Projects
None yet
Development

No branches or pull requests

1 participant