Skip to content

Conversation

mkrasnitski
Copy link
Collaborator

@mkrasnitski mkrasnitski commented Jul 17, 2025

This PR splits serenity into two crates, serenity and serenity-core.

  • The core library contains the builder, cache, http, model, and utils modules.
  • The serenity crate depends on the core and re-exports everything in it, plus it also contains the gateway, collector, framework, and interactions_endpoint modules. It also re-exposes all of the core's feature flags, though I'm not sure if that's the right approach.

Further splitting may be possible in the future but would require significant refactoring to remove circular dependencies between modules. For error propagation, a bunch of variants on serenity::Error got moved into the core, and are propagated using Error::Core which wraps a serenity_core::Error. Though, I wonder if it's better to keep the variants and convert 1-1 from a serenity_core::Error so as to keep things more flat.

@github-actions github-actions bot added utils Related to the `utils` module. gateway Related to the `gateway` module. examples Related to Serenity's examples. collector Related to the `collector` module. labels Jul 17, 2025
@mkrasnitski mkrasnitski force-pushed the crate-split branch 2 times, most recently from 84fc566 to 1ee1318 Compare July 17, 2025 11:53
@mkrasnitski
Copy link
Collaborator Author

Ran some compile-time benchmarks on my machine using hyperfine and came up with some numbers. Before this PR:

Benchmark 1: cargo check
  Time (mean ± σ):     14.868 s ±  0.049 s    [User: 60.332 s, System: 9.855 s]
  Range (min … max):   14.760 s … 14.931 s    10 runs

Benchmark 2: cargo build
  Time (mean ± σ):     19.035 s ±  0.059 s    [User: 83.263 s, System: 11.827 s]
  Range (min … max):   18.945 s … 19.098 s    10 runs

Benchmark 3: cargo build --release
  Time (mean ± σ):     24.560 s ±  0.291 s    [User: 195.193 s, System: 12.501 s]
  Range (min … max):   24.159 s … 25.139 s    10 runs

After this PR:

Benchmark 1: cargo check
  Time (mean ± σ):     14.478 s ±  0.054 s    [User: 59.951 s, System: 9.903 s]
  Range (min … max):   14.377 s … 14.572 s    10 runs

Benchmark 2: cargo build
  Time (mean ± σ):     17.117 s ±  0.036 s    [User: 82.604 s, System: 12.095 s]
  Range (min … max):   17.079 s … 17.185 s    10 runs

Benchmark 3: cargo build --release
  Time (mean ± σ):     22.155 s ±  0.143 s    [User: 199.097 s, System: 12.608 s]
  Range (min … max):   21.930 s … 22.431 s    10 runs

If we compare mean execution times, that gives a 2.6% improvement for cargo check, 10.1% improvement for cargo build, and 9.8% improvement for cargo build --release.

@github-actions github-actions bot removed the utils Related to the `utils` module. label Jul 25, 2025
@mkrasnitski mkrasnitski force-pushed the crate-split branch 3 times, most recently from 7c5f769 to e49f8ef Compare July 26, 2025 22:21
@mkrasnitski mkrasnitski marked this pull request as ready for review July 26, 2025 23:04
@mkrasnitski
Copy link
Collaborator Author

This PR is ready for review now

@arqunis arqunis added enhancement An improvement to Serenity. breaking change The public API is changed, resulting in miscompilations or unexpected new behaviour for users labels Aug 31, 2025
Copy link
Member

@GnomedDev GnomedDev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, and a good start to splitting apart serenity.

I would be interested in seeing what the difference in cargo build --timings looks like, specifically with a poise or songbird based bot to see if they can depend only on core and kick off their build earlier.

I haven't taken a deep look over this, but spotted this comment immediately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking change The public API is changed, resulting in miscompilations or unexpected new behaviour for users collector Related to the `collector` module. enhancement An improvement to Serenity. examples Related to Serenity's examples. gateway Related to the `gateway` module.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants