{"id":16528363,"url":"https://github.com/danvk/rusty-boggle","last_synced_at":"2025-08-02T10:34:00.479Z","repository":{"id":66069064,"uuid":"351204903","full_name":"danvk/rusty-boggle","owner":"danvk","description":"A boggle solver in Rust","archived":false,"fork":false,"pushed_at":"2021-03-24T19:49:59.000Z","size":19,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-07T16:09:10.651Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/danvk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-03-24T19:49:38.000Z","updated_at":"2021-03-24T20:35:47.000Z","dependencies_parsed_at":"2023-03-25T23:49:26.721Z","dependency_job_id":null,"html_url":"https://github.com/danvk/rusty-boggle","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/danvk/rusty-boggle","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danvk%2Frusty-boggle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danvk%2Frusty-boggle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danvk%2Frusty-boggle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danvk%2Frusty-boggle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/danvk","download_url":"https://codeload.github.com/danvk/rusty-boggle/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danvk%2Frusty-boggle/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268371663,"owners_count":24239793,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-02T02:00:12.353Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-11T17:40:01.859Z","updated_at":"2025-08-02T10:34:00.427Z","avatar_url":"https://github.com/danvk.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Rusty Boggle\n\nPort of [performance boggle][1] to Rust. While I've [known a lot about Boggle][2] at points in the past, I'm a bit rusty.\n\n## Porting\n\nI'm going off the `paper` version of Boggle in performance-boggle, which was intended to be clean.\n\nTrie\nBoggler\nPerf test\n\nIs `[Option\u003cTrie\u003e; NUM_LETTERS]` as efficient as `Trie*` in terms of memory layout? How can I tell?\n\nThe \"mark\" optimization is going to be trick since all the Tries will need to be mutable.\n\nAre `struct` members public? How does access control work?\n\nWhat is Rust naming convention? `my_method` or `myMethod`? Is there a preference?\n\nvscode stopped showing errors / autocomplete in a way that makes me uncomfortable.\n--\u003e I got no error checking / language services until I imported from `main.rs`.\n\nInitializing this structure was surprisingly hard:\n\n    children: [Option\u003cBox\u003cTrie\u003e\u003e; NUM_LETTERS],\n\nI got a reference to a GitHub issue when I tried `[None; NUM_LETTERS]`!\nhttps://github.com/rust-lang/rust/issues/49147\n\nUnit tests live in the same file as their code, in a `tests` module.\nThe \"if it compiles it works\" mantra seems to be holding up well so far.\n\nIs there any way to automatically call `destroy` methods when a structure is consumed?\n\nIs there a pattern for de-duping code between a mut and non-mut method?\n\nIt's going to pay off to get very, very comfortable with idiomatic `Option` usage.\n- It's not really clear to me when I can use `flat_map`.\n- The trailing `?` operator is helpful.\n- Is there an equivalent of refinement? i.e. panic on Err\n\nIt seems like sometimes `Box` gets implicitly unwrapped in ways that confuse me.\nFor example, this looks like it should be the identity:\n\n    Some(c) =\u003e match c {\n        Some(d) =\u003e Some(d),\n        None =\u003e None,\n    }\n\nBut `c` is `\u0026Option\u003cBox\u003cTrie\u003e\u003e`, so it actually secretly unboxes the Trie.\nIs there a shorter way to write this?\n\nFirst cut:\n\n    $ time ./target/debug/rusty-boggle ../performance-boggle/words\n    Loaded 173528 words into 389309 nodes from ../performance-boggle/words\n    ./target/debug/rusty-boggle ../performance-boggle/words  1.79s user 0.04s system 99% cpu 1.843 total\n\nI'm a little worried about that performance while loading the Trie.\n\nWow, writing functions from str -\u003e str is complicated!\nhttps://stackoverflow.com/questions/29781331/why-cant-i-return-an-str-value-generated-from-a-string\n\nArray indexing has been a bit painful. To index into an array, you need a `usize`.\nBut to subtract one from the x position, you need to do `x - 1`, or `x + (-1)`, which could overflow.\nThis is all pretty annoying to model out!\n\nI'm confused by how hard it is to import modules in Rust.\nI have:\nsrc/\n  boggler.rs\n  trie.rs\n  main.rs\n\nTo import trie.rs from boggler.rs, I had to do this:\n\n    #[path = \"./trie.rs\"]\n    mod trie;\n\nBut then in `main.rs`, I get this:\n\n    mismatched types\n    expected struct `boggler::trie::Trie`, found struct `trie::Trie` rustc(E0308)\n\nAs though these weren't the same. Apparently the trick is `crate`:\n\n    use crate::trie;\n\nThis _only_ works if you also have `mod trie` in `main.rs`.\nThis also doesn't work from a file in `bin/prog.rs`.\n\nYou can't mutate parameters as you can in C or JS.\n\nThe mutable Trie is making me fight with the borrow checker.\nThis is a big performance win (it means you don't need a cleanup) but I can see why rust thinks it's unsafe.\nMy workaround is to disentangle ownership of the Boggler \u0026 the Trie.\nI don't think this is good from a safety perspective.\n\nUnclear if you're allowed to compare pointers for equality in Rust:\nhttps://users.rust-lang.org/t/is-any-way-to-know-references-are-referencing-the-same-object/9716/5\nThis makes me wonder if choosing such a performance-sensitive application was good for a first project!\n\n`vec.iter().enumerate()` is a useful pattern: iterate over (index, value) pairs.\n\nFirst indication of performance (debug build, incorrect results):\n\n    Evaluated 216320 boards in 14.541386 seconds = 14876.161 bds/sec\n\nTo do an optimized build, you run `cargo build --release`.\n\nThe release build is much faster:\n\n    ~Evaluated 216320 boards in 2.0822232 seconds = 103888.96 bds/sec~\n    Evaluated 216320 boards in 1.6475447 seconds = 131298.4 bds/sec\n\nI'd left a debug line in the performance test. I'm pretty surprised this made a 20k bds/sec\ndifference; it looks like it should be much cheaper than scoring a board:\n\n    boggler.parse_board(\u0026boggler.to_string()).unwrap();\n\nBut still only ~half the speed of the C++ version:\n\n    Evaluated 216320 boards in 0.929824 seconds = 232646.209370 bds/sec\n\nSome notes from reading about lifetimes and generics in the Rust book:\n\n- In general Rust uses move semantics for complex objects and copy for primitives.\n  This is decided by whether a type implements the `Copy` trait.\n  The upshot is that there are generally no implicit and expensive operations like in C++.\n- Originally, reference parameters _always_ required lifetime annotations.\n  To streamline things, there are two special cases:\n  1. If there's only one input reference, the output reference gets its lifetime.\n  2. Output references get the lifetime of `\u0026self`.\n- You usually want to take `\u0026str` as a parameter and return either:\n  - `\u0026str` (if it's a slice or the whole input) or\n  - `String` if it isn't, which forces the caller to take ownership.\n\n~A BUG! In my 13 year old C++ code, no less. It doesn't find \"suqu\" on the board \"czzdlqzemauopezs\".~\n~The web UI for this board has many bugs: \u003chttps://www.danvk.org/boggle/?board=czzdlquzemauopezs\u003e.~\n\nThe word was \"suq\", not \"suqu\". So it's not a Boggle word.\n\nMain questions I have now:\n\n1. Is there a more idiomatic way to write my Boggler? Main questions here:\n   1. How can I make the Boggler take ownership of the Trie?\n   2. How can I use debug methods like `reverse_lookup` w/o angering the borrow checker?\n   3. Is there a better way to do the `neighbors` iterator?\n2. Why is it slower than C++? Some ideas:\n   1. The `neighbors` iterator.\n   2. Try inlining the `HIT` macro from C++.\n   3. The `Box` wrapper in `Trie`.\n      --\u003e Inverting this is actually much slower! (See commit 29c0acd)\n      -children: [Box\u003cOption\u003cTrie\u003e\u003e; NUM_LETTERS],\n      +children: Box\u003c[Option\u003cTrie\u003e; NUM_LETTERS]\u003e,\n      Evaluated 216320 boards in 2.1912093 seconds = 98721.74 bds/sec\n\nThere is a `cargo flamegraph` command for profiling: https://github.com/flamegraph-rs/flamegraph\n... sadly it does not work on macOS because of security https://github.com/flamegraph-rs/flamegraph/issues/31\n\nEven after reading the relevant chapter in the Rust book, I'm still finding the file organization of modules baffling.\nhttps://www.reddit.com/r/rust/comments/6ow7q9/how_to_structure_a_multibinary_multimodule_project/\n\nThis repo helped me figure it out:\nhttps://github.com/shepmaster/sxd-document/blob/master/src/bin/open.rs\n\nThe trick was to do two things:\n\n1. Make a file `src/lib.rs` which declares all the other lib files with `pub mod`.\n2. Import from files in `bin/` via `use rusty_boggle::boggler`;\n   This wasn't necessary in `main.rs`, but seems to be necessary in `bin/prog.rs`.\n\nThis is all pretty confusing.\n\n## General Notes\n\n- \"Classic\" C++ is really drowning in type annotations.\n- I'm seeing a 3-10x speedup on my 2020 macBook Pro vs. what I recorded ~10y ago:\n  $ ./4x4/perf_test\n  Evaluated 216320 boards in 0.953688 seconds = 226824.728068 bds/sec\n  vs README.md: \"88889.509057 bds/sec\"\n  and 4x4/perf_test.cc: \"~20kbds/sec\"\n- The README references \"max+one\" but I don't see this in the code.\n  Maybe there's a newer version in a repo somewhere?\n- Some of the files in the repo are 13 years old.\n  I didn't think GitHub was that old; maybe this is an svn import?\n- The repo is well-organized; I particularly like the subdirectories with abandoned ideas and short explanations of why they didn't pan out.\n\nInteresting reading this comment with \"Don't put type information in the documentation\":\n\n    // Assumes ownership of the Trie. No other Boggler may modify the Trie after\n    // this Boggler has been constructed using it.\n    Boggler(TrieT* t);\n\nFrom a Rust perspective, that's type information!\n\n[1]: https://github.com/danvk/performance-boggle\n[2]: http://www.danvk.org/wp/category/boggle/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanvk%2Frusty-boggle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanvk%2Frusty-boggle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanvk%2Frusty-boggle/lists"}