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

Add configure command to native messaging interface #103

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jelmervdl
Copy link
Collaborator

Useful for benchmarking mostly

Useful for benchmarking mostly
@@ -359,13 +370,21 @@ request_variant NativeMsgIface::parseJsonInput(QByteArray input) {
ret.id = id;
for (auto&& key : mandatoryKeysDownload) {
QJsonValueRef val = data[key];
if (val.isNull()) {
if (val.isNull() || val.isUndefined()) {
Copy link
Owner

@XapaJIaMnu XapaJIaMnu May 5, 2022

Choose a reason for hiding this comment

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

So... isNull() is like key: "", whereas isUndefined() is the key is not found at all?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Owner

Choose a reason for hiding this comment

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

How was it then working beforehand!?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I have no idea, nor have I tested missing keys properly? They definitely look pretty distinct and incompatible:

inline bool isNull() const { return type() == Null; }
...
inline bool isUndefined() const { return type() == Undefined; }

(From qjsonvalue.h#107-113)

@XapaJIaMnu
Copy link
Owner

Good! I should make use of this to add automatic tests on githubCI!

@jelmervdl
Copy link
Collaborator Author

I marked it as draft because I just implemented this as a one-off for some benchmarking work. However, this functionality might be useful for other use cases as well.

There should be probably be a min(requested-threads, std::thread::hardware_concurrency()) or something.

@XapaJIaMnu
Copy link
Owner

Yeah, that's what I do: https://github.com/XapaJIaMnu/translateLocally/blob/master/src/settings/TranslatorSettingsDialog.cpp#L24
Should that be written to settings if changed?

@jelmervdl
Copy link
Collaborator Author

jelmervdl commented May 5, 2022

I'd say no, that would be unexpected. I like the idea that it will default to whatever you selected in the GUI, but you can reconfigure it easily if you want something specific for that session/client application.

In my measurements, the Configure command is pretty much free when it is the first command issued. bergamot-translator's AsyncService does almost no work until the first translation is requested.

@jelmervdl
Copy link
Collaborator Author

Oeh note to self: it should do everything from the pointer reset line in std::async or something, because that's a blocking call that will wait for all still pending translations to finish. And that should not be blocking the event loop!

And then I need to think a bit about how it should treat translation requests that come in after the Configure command. They should be queued/processed after it, and not to the service that is about to be reset (thereby delaying the reset even more). So maybe the reset() should be blocking the event loop?

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