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

Better multithreading options #84

Merged
merged 7 commits into from
Aug 8, 2024
Merged

Conversation

MyBlackMIDIScore
Copy link
Member

  • Control the number of threads used in threadpools (in ChannelGroup and RealtimeSynth)
  • Control whether a threadpool will be used when rendering channels in a ChannelGroup
  • Modified the rendered module config and removed defaults (because it includes the channel group config now which doesn't have defaults due to the stream params)
  • Off-topic: Removed and ignored vscode config from the repo so everyone can use their own lol

Copy link
Collaborator

@arduano arduano left a comment

Choose a reason for hiding this comment

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

The rest lgtm, nice work

/// [this](https://docs.rs/rayon-core/1.11.0/rayon_core/struct.ThreadPoolBuilder.html#method.num_threads)
/// for more information.
#[derive(Clone)]
pub struct ParallelismOptions {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Some(0) isn't really a good magic value, that's why we use enums lol.

E.g. "pub enum ThreadCount" with options One, Auto, Manual(u32) or something like that, where Auto just uses the core count

Also It's nice to have constants for these things, because 90% of use cases are just "auto multithreading per channel" or "auto multithreading per channel per key"

Copy link
Member Author

Choose a reason for hiding this comment

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

E.g. "pub enum ThreadCount" with options One, Auto, Manual(u32) or something like that, where Auto just uses the core count

True that sounds like a better approach. Should also be easier for the user to understand what is going on.

Also It's nice to have constants for these things, because 90% of use cases are just "auto multithreading per channel" or "auto multithreading per channel per key"

You mean make a constant of the enum:

const AUTO_MULTITHREADING: ThreadCount = ThreadCount::Auto

or the struct itself:

const AUTO_MULTITHREADING: ParallelismOptions = ParallelismOptions {
    channel: ThreadCount::Auto,
    key: ThreadCount::Auto,
}

?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Nah I meant making it a constant implemented on the struct, you can have const fields inside impl blocks

Copy link
Member Author

Choose a reason for hiding this comment

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

So like this or a function that returns it?

impl ParallelismOptions {
    const AUTO: Self = ParallelismOptions {
        channel: ThreadCount::Auto,
        key: ThreadCount::Auto,
    };
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah that, except AUTO_PER_KEY (key and channel) and AUTO_PER_CHANNEL (just channel) with descriptions for each, and an Default implementation that does auto per key

Copy link
Collaborator

Choose a reason for hiding this comment

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

In my opinion at least

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah that, except AUTO_PER_KEY (key and channel) and AUTO_PER_CHANNEL (just channel) with descriptions for each, and an Default implementation that does auto per key

Alright yeah that sounds good. Shouldn't default be auto for both though? It was like that before (at least for channel).

core/src/channel_group/mod.rs Outdated Show resolved Hide resolved
realtime/src/config.rs Outdated Show resolved Hide resolved
@MyBlackMIDIScore
Copy link
Member Author

Made the changes, let me know if you meant something else or if there's anything else I should change.
Perhaps the documentation, I am still not sure about it (mostly about the new ones I just added lol)

@arduano
Copy link
Collaborator

arduano commented Aug 8, 2024

Anyway just add the constants stuff and I'll check again when I wake up


impl ParallelismOptions {
pub const AUTO_PER_KEY: Self = ParallelismOptions {
channel: ThreadCount::None,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should be auto here still, because if you're parallelizing voice processing per key you'd probably also want to parallelize event processing too (which must happen per channel)

Suggested change
channel: ThreadCount::None,
channel: ThreadCount::Auto,

Copy link
Member Author

Choose a reason for hiding this comment

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

True, will change this and also use this const for Default. Is it ok to merge after this change?

Copy link
Collaborator

Choose a reason for hiding this comment

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

yeah

@MyBlackMIDIScore MyBlackMIDIScore merged commit 4907fe0 into master Aug 8, 2024
1 check passed
@MyBlackMIDIScore MyBlackMIDIScore deleted the threadpool-options branch August 8, 2024 21:41
Kaydax pushed a commit that referenced this pull request Aug 21, 2024
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.

2 participants