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

Lazy model switch #210

Merged
merged 30 commits into from
Aug 16, 2024
Merged

Lazy model switch #210

merged 30 commits into from
Aug 16, 2024

Conversation

noxware
Copy link
Collaborator

@noxware noxware commented Aug 8, 2024

@@ -538,7 +541,11 @@ impl WidgetMatchEvent for ChatPanel {
self.redraw(cx);
}
ChatLineAction::Edit(id, updated, regenerate) => {
store.chats.edit_chat_message(id, updated, regenerate);
if regenerate {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The flag was completely changing what the function does, so I spitted the function (motivated by this).

_ => false,
};

let text_enabled_color = hex_rgb_color(0x000000);
Copy link
Collaborator Author

@noxware noxware Aug 9, 2024

Choose a reason for hiding this comment

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

I don't know if makepad gives us some helper to build vec4 colors outside of the DSL so I made this util.
This avoids needing to clarify which color this vector represents and also is recognized by vs code extensions like colorize.

image

let command_sender = backend.command_sender.clone();
thread::spawn(move || {
if let Err(err) = model_loader.load_blocking(wanted_file.id, command_sender.clone()) {
eprintln!("Error loading model: {}", err);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Future idea: Eventually, all eprintln we have around in the codebase could trigger a Cx::post_action(ErrorNotification(...)) with the latest updates in makepad, to get feedback in the UI.

Self::default()
}

pub fn load_blocking(
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Having blocking functions by default instead of implicit threading functions makes code more composable and avoids creating extra threads when you are already in a separate synchronous thread (like the thread spawned by send message function).


pub fn load(&mut self, file_id: FileID, command_sender: Sender<Command>) {
Copy link
Collaborator Author

@noxware noxware Aug 9, 2024

Choose a reason for hiding this comment

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

Provided just to have a function with the previous behavior although, forcing the caller to be explicit about spawning a thread would be also an option.

pub fn load_blocking(
&mut self,
file_id: FileID,
command_sender: Sender<Command>,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The backend type is just this actually and this works better in multithreading contexts as you can clone it. We could make the Backend type Clone just to have the pretty type backend: Backend and also remove the Rc<Backend> we have in store but is not a big deal for me.

@noxware noxware marked this pull request as ready for review August 9, 2024 21:12
src/data/chats/mod.rs Show resolved Hide resolved
src/data/chats/model_loader.rs Outdated Show resolved Hide resolved
src/data/chats/model_loader.rs Outdated Show resolved Hide resolved
src/chat/model_selector.rs Show resolved Hide resolved
@noxware noxware force-pushed the lazy-model-switch branch from f468606 to f807178 Compare August 12, 2024 15:31
src/chat/model_selector.rs Outdated Show resolved Hide resolved
@noxware noxware force-pushed the lazy-model-switch branch from a3c0e56 to 4d486f1 Compare August 12, 2024 20:28
@noxware noxware force-pushed the lazy-model-switch branch from 4d486f1 to 2d0dd6e Compare August 12, 2024 20:29
@noxware noxware force-pushed the lazy-model-switch branch from 3a42db2 to f1865ea Compare August 13, 2024 17:21
Copy link
Collaborator

@jmbejar jmbejar left a comment

Choose a reason for hiding this comment

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

Good job!

@jmbejar jmbejar merged commit 7f3c2ca into dev Aug 16, 2024
5 checks passed
@jmbejar jmbejar deleted the lazy-model-switch branch August 16, 2024 18:52
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.

3 participants