chore: drop unused malloc_conf, idiomatic cleanups, and first tests for src/jobs/ - #796
chore: drop unused malloc_conf, idiomatic cleanups, and first tests for src/jobs/#796manan19 wants to merge 7 commits into
Conversation
Drops jemalloc as the global allocator so the project builds on paths containing spaces (jemalloc's configure script rejects those). Also applies mechanical cleanups and adds the first tests for src/jobs/, which previously had zero coverage. Changes: - Remove jemalloc (tikv-jemallocator, tikv-jemalloc-ctl, rocksdb "jemalloc" feature, #[global_allocator] + malloc_conf, and the emit_jemalloc_stats hook). Relates to #780. - Replace 53 occurrences of `.len() == 0` / `.len() > 0` with `is_empty()` / `!is_empty()` across 19 files. Supersedes #592. - Lazy-compile the 4 module-level regexes in core/validations/message.rs using once_cell::Lazy so each regex compiles once instead of on every validation call. Aligns with #576. - Add 13 unit tests for src/jobs/ (block_pruning, event_pruning, snapshot_upload, migrate_onchain_events) covering job creation, cutoff timestamp math, sync-gate behavior, stale-backup cleanup, in-progress detection, empty-store migration, and mempool backpressure. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Pull request overview
This PR bundles several repo-wide cleanups and small improvements: removing jemalloc integration, making emptiness checks more idiomatic, optimizing message validation regex usage, and adding initial unit tests for the jobs modules.
Changes:
- Remove jemalloc allocator/stats plumbing and related dependencies/features (including RocksDB’s
jemallocfeature). - Replace many
.len() == 0/.len() > 0checks withis_empty()/!is_empty()across the codebase. - Compile validation regexes once via
once_cell::sync::Lazyand add unit tests forsrc/jobs/*.
Reviewed changes
Copilot reviewed 26 out of 27 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
src/utils/statsd_wrapper.rs |
Removes jemalloc stats emission helper. |
src/lib.rs |
Removes global jemalloc allocator and malloc_conf export. |
Cargo.toml |
Drops jemalloc-related deps/features; adds filetime dev-dependency; removes RocksDB jemalloc feature. |
Cargo.lock |
Updates lockfile to reflect removed jemalloc crates and added filetime. |
src/core/validations/message.rs |
Switches regex compilation to Lazy statics and updates call sites; some is_empty() refactors. |
src/core/validations/verification.rs |
Refactors byte-vector emptiness checks to is_empty(). |
src/core/types.rs |
Refactors an assert to !is_empty(). |
src/consensus/consensus.rs |
Refactors asserts to !is_empty(). |
src/consensus/malachite/read_sync.rs |
Refactors peer emptiness check to is_empty(). |
src/network/http_server.rs |
Refactors base64 empty-string check to is_empty(). |
src/network/gossip.rs |
Refactors config string presence checks to !is_empty(). |
src/mempool/block_receiver.rs |
Refactors event emptiness checks to is_empty(). |
src/storage/trie/trie_node.rs |
Refactors emptiness checks to is_empty() / !is_empty(). |
src/storage/store/shard.rs |
Refactors pagination token check to !is_empty(). |
src/storage/store/block.rs |
Refactors pagination token check to !is_empty(). |
src/storage/store/account/username_proof_store.rs |
Refactors string/vector emptiness checks and conflict list checks. |
src/storage/store/account/reaction_store.rs |
Refactors pagination token check to !is_empty(). |
src/storage/store/account/onchain_event_store.rs |
Refactors pagination token checks to !is_empty(). |
src/storage/store/account/message.rs |
Refactors pagination token and data_bytes presence/emptiness checks. |
src/storage/store/account/link_store.rs |
Refactors validations/emptiness checks; simplifies some conditions. |
src/storage/store/account/event.rs |
Refactors pagination token check to !is_empty(). |
src/storage/store/account/cast_store.rs |
Refactors pagination token checks to !is_empty(). |
src/storage/store/account/block_event_store.rs |
Refactors pagination token check to !is_empty(). |
src/jobs/snapshot_upload.rs |
Removes jemalloc stats calls and adds unit tests for snapshot upload behavior. |
src/jobs/migrate_onchain_events.rs |
Removes TODO attribution in comment and adds unit tests around migration behavior/backpressure. |
src/jobs/event_pruning.rs |
Adds unit tests for job creation and retention math. |
src/jobs/block_pruning.rs |
Adds unit tests for job creation and sync gate behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
LazyLock is stable since Rust 1.80 and the project builds on 1.95 with no pinned MSRV, so the std version is preferred over the external crate for this use case. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The is_empty() simplification in link_store.rs removed redundant `.len() == 0` checks that were logically unreachable, but the error branches (empty type with target, overlong type) had no existing test coverage. These 6 regression tests lock in the current behavior so future refactors catch drift. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diff CoverageDiff: origin/main...HEAD, staged and unstaged changes
Summary
src/consensus/consensus.rssrc/core/validations/message.rssrc/jobs/block_pruning.rssrc/jobs/event_pruning.rssrc/jobs/migrate_onchain_events.rssrc/jobs/snapshot_upload.rssrc/network/http_server.rssrc/storage/store/account/link_store_test.rs |
ts_hash is Option<&[u8; TS_HASH_LENGTH]> (24 bytes), so is_empty() on the inner slice can never return true. The branch has always been dead code; removing it per PR review. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
topocount
left a comment
There was a problem hiding this comment.
Removing jemalloc as a rocksdb feature breaks a bunch of the memory management improvements we've been working on
Per PR review (#796), the original commit removed too much. jemalloc remains the global allocator and the tikv-jemallocator / tikv-jemalloc-ctl deps + rocksdb \"jemalloc\" feature stay in place. Only the malloc_conf export — which was unused as topocount noted in the original #780 proposal — is removed. emit_jemalloc_stats and its callers are restored. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
manan19
left a comment
There was a problem hiding this comment.
Thanks for the feedback. Splitting into separate PRs:
- #796 (this PR) — will close in favor of the splits below;
malloc_confremoval already covered by your #780, no separate PR needed - PR A:
.len() == 0/.len() > 0→is_empty()refactor (53 occurrences across 19 files), plus the relatedlink_store.rssimplifications and the regression tests inlink_store_test.rs - PR B: Lazy regex compilation in
core/validations/message.rsviastd::sync::LazyLock - PR C: First tests for
src/jobs/(13 new tests across 4 modules)
Will open these as separate PRs and link them here once they're up.
|
Closing in favor of the split-out PRs per @topocount's review:
|
## Summary The `src/jobs/` directory had zero test coverage despite running production-critical pruning, snapshot upload, and on-chain event migration logic. Adds 13 inline `#[cfg(test)]` tests across all four modules: - **`block_pruning`** (4 tests) — job creation succeeds in both sync states; sync gate semantics (skips when not synced, runs when synced) - **`event_pruning`** (3 tests) — job creation; cutoff timestamp = `farcaster_time - retention.as_secs()`; longer retention prunes further back - **`snapshot_upload`** (4 tests) — `UploadAlreadyInProgress` returned when backup dir has recent contents; empty `only_for_shard_ids` filter skips all backups; stale-backup contents cleaned up when mtime is older than 12h; `STALE_BACKUP_THRESHOLD` constant is exactly 12 hours - **`migrate_onchain_events`** (2 tests) — empty store completes migration immediately (fast exit before `wait_for_mempool_to_clear`); mempool backpressure waits and recovers when size drops below `MAX_MEMPOOL_SIZE` Adds `filetime = "0.2"` as a `[dev-dependencies]` entry for the stale-backup test (used to set an old mtime on the temp directory). Split out from #796 per review feedback. ## Test plan - [x] `cargo test jobs` passes (13/13) 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
## Summary The 4 constant-source regexes in `core/validations/message.rs` (`FNAME_REGEX`, `TWITTER_USERNAME_REGEX`, `GITHUB_USERNAME_REGEX`, geo) were being recompiled with `fancy_regex::Regex::new(...)` on every call to `validate_fname`, `validate_ens_name`, `validate_base_name`, `validate_twitter_username`, `validate_github_username`, and `validate_user_location`. Each is hot-path validation code. Moves them to module-level `static LazyLock<Regex>` so each compiles exactly once. The CAIP-19 regex is dynamically constructed from a local variable (depends on namespace input), so it's left as-is. Aligns with the intent of #576; uses stable `std::sync::LazyLock` (stabilized in Rust 1.80) instead of `lazy_static!` or `once_cell`. Split out from #796 per review feedback. ## Test plan - [x] All 78 existing validation tests pass 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
## Summary Mechanical Clippy-style refactor: `.len() == 0` → `.is_empty()` and `.len() > 0` → `!x.is_empty()` across 21 files (49 occurrences). `verification.rs` is already handled by #827, so this PR skips it. Also includes a few related simplifications in `link_store.rs` that the refactor surfaced: - Drop duplicate `is_empty() || .len() == 0` checks in `link_add_key` / `link_remove_key` — the OR-clauses were logically redundant. - Remove unreachable `is_empty()` check on `Option<&[u8; 24]>` — a fixed-size 24-byte array reference can never be empty (caught in PR #796 review). - Simplify `data_bytes.is_some() && data_bytes.as_ref().unwrap().len() > 0` in `store/account/message.rs` to `data_bytes.as_ref().is_some_and(|b| !b.is_empty())`. Adds 6 regression tests in `link_store_test.rs` covering the error branches in `link_add_key` / `link_remove_key` (`"targetId provided without type"`, `"link type invalid"`) which had no prior direct test coverage. Supersedes #592. Split out from #796 per review feedback. ## Test plan - [x] `cargo test` passes locally - [x] `cargo fmt --check` passes - [x] 6 new `link_store_test` regression tests pass 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Summary
A bundle of low-risk cleanups plus the first test coverage for
src/jobs/, each verified with tests passing before and after.Changes
malloc_confexport. Thepub static malloc_confinlib.rswas never exported with the_rjem_prefix that jemalloc actually reads, so it was dead code. Same scope as @topocount's chore: remove unused jemalloc configs #780. Jemalloc itself stays as the global allocator;tikv-jemallocator,tikv-jemalloc-ctl, the rocksdb"jemalloc"feature, andemit_jemalloc_statsall remain unchanged..len() == 0/.len() > 0→is_empty()/!is_empty(). 53 occurrences across 19 files. Also simplified a few duplicate / unreachable checks inlink_store.rs(including one caught by review whereis_empty()was called on an&[u8; 24]). Supersedes refactor: use is_empty() instead of len() > 0 checks in perftest.rs #592.core/validations/message.rs. The 4 module-level regexes (FNAME,TWITTER_USERNAME,GITHUB_USERNAME, geo) are now compiled once viastd::sync::LazyLockinstead of on every validation call. Aligns with the intent of perf: optimize regex compilation with lazy_static #576; uses stable std (available since Rust 1.80) rather thanlazy_static!oronce_cell.src/jobs/(13 new). This directory previously had zero coverage. Added inline#[cfg(test)]modules covering job creation, cutoff timestamp math, sync-gate behavior, stale-backup cleanup, in-progress detection, empty-store migration, and mempool backpressure.link_store(6 new, in the existinglink_store_test.rs). Covers the error branches ("targetId provided without type","link type invalid") that theis_empty()simplification touched, which had no prior direct coverage.Related issues / PRs
malloc_confremoval (this PR carries the same scope)is_empty()refactor (this PR supersedes it)std::sync::LazyLockinstead oflazy_static!)Test plan
cargo testpasses (632/632)cargo fmt --checkpassescargo test jobspasses (13/13)link_storeregression tests pass (6/6)🤖 Generated with Claude Code