Skip to content

feat: parallelize multimodal decode in request transfer.#1474

Open
wly-115 wants to merge 1 commit into
jd-opensource:mainfrom
wly-115:feat/parallel_decode
Open

feat: parallelize multimodal decode in request transfer.#1474
wly-115 wants to merge 1 commit into
jd-opensource:mainfrom
wly-115:feat/parallel_decode

Conversation

@wly-115
Copy link
Copy Markdown
Collaborator

@wly-115 wly-115 commented May 18, 2026

No description provided.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the multi-modal input processing logic to enable parallel decoding. The MMHandlerSet::process method is split into load and decode phases, and MMInputTransfer now utilizes a ThreadPool and BlockingCounter to execute decoding tasks concurrently. Feedback focuses on adhering to the repository style guide, specifically regarding project-root-relative include paths, annotating constant arguments, reserving vector capacity, using early continue in loops to reduce nesting, and applying static_cast for type conversions.

Comment on lines +23 to +24
#include "util/blocking_counter.h"
#include "util/threadpool.h"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

According to the repository style guide, all includes must use project-root-relative paths. The current paths are missing the core/ prefix.

Suggested change
#include "util/blocking_counter.h"
#include "util/threadpool.h"
#include "core/util/blocking_counter.h"
#include "core/util/threadpool.h"
References
  1. No relative paths in #include. Always use project-root-relative paths. (link)


MMInputTransfer::MMInputTransfer() {
mm_handlers_ = std::make_unique<MMHandlerSet>();
threadpool_ = std::make_unique<ThreadPool>(16);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

Constant arguments in constructor calls should be annotated with the parameter name to improve readability, as per the repository style guide.

Suggested change
threadpool_ = std::make_unique<ThreadPool>(16);
threadpool_ = std::make_unique<ThreadPool>(/*num_threads=*/16);
References
  1. Annotate constant arguments with a comment indicating the parameter name when calling functions or constructors. (link)

@@ -50,22 +61,69 @@ MMErrCode MMInputTransfer::trans(const MMContentVec& mmc,
std::vector<MMInputItem>& inputs,
MMPayload& payload) {
inputs.clear();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

The repository style guide requires calling reserve() before filling a std::vector when the size is known or can be estimated. Since mmc.size() is known, we should reserve capacity for inputs.

Suggested change
inputs.clear();
inputs.clear();
inputs.reserve(mmc.size());
References
  1. Always reserve() before filling a std::vector when the size is known or can be estimated. (link)

Comment on lines 71 to 83
if (type != "text") {
MMInputItem input;
MMErrCode code = mm_handlers_->process(type, item, input, payload);
MMErrCode code = mm_handlers_->load(type, item, input, payload);
if (code != MMErrCode::SUCCESS) {
return code;
}

inputs.emplace_back(std::move(input));
decode_tasks.emplace_back(DecodeTask{
.type = type,
.input_index = inputs.size() - 1,
});
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

The repository style guide recommends avoiding if blocks inside for loops for filtering logic. Using an early continue reduces indentation and improves readability.

    if (type == "text") {
      continue;
    }
    MMInputItem input;
    MMErrCode code = mm_handlers_->load(type, item, input, payload);
    if (code != MMErrCode::SUCCESS) {
      return code;
    }

    inputs.emplace_back(std::move(input));
    decode_tasks.emplace_back(DecodeTask{
        .type = type,
        .input_index = inputs.size() - 1,
    });
References
  1. Avoid if inside for loops when possible. Prefer filtering the data beforehand or restructuring the logic (e.g., early continue). (link)

return MMErrCode::SUCCESS;
}

BlockingCounter counter(decode_tasks.size());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

The repository style guide requires using static_cast for all type conversions. Converting size_t to int32_t (as required by the BlockingCounter constructor) should be explicit.

Suggested change
BlockingCounter counter(decode_tasks.size());
BlockingCounter counter(static_cast<int32_t>(decode_tasks.size()));
References
  1. Use static_cast for all type conversions. Never use C-style casts. (link)

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.

1 participant