镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Support for batched translation #85

Open

Description

@sushraja-msft

A limitation we observe with the translate API is that it processes one input at a time.

Our investigation shows that batched inference significantly improves performance on CPU, we see a 2‑fold performance gain with a batch size greater than 32, which we believe is due to lower kernel dispatch, scheduling overhead, better tiling, and improved hardware utilization.

From a developer perspective, use cases are translating content across multiple unrelated elements or several individual user-generated comments on a page require passing a collection of strings (with independent context) and translating them together with the source sentence identity preserved so that they can be replaced back in the DOM.

Concretely, the proposal is to support two overloads on the translate, translateStreaming API.

 Promise<sequence<DOMString>> translate(
    sequence<DOMString> inputs,
    optional TranslatorTranslateOptions options = {}
  );

  ReadableStream translateStreaming(
    sequence<DOMString> input,
    optional TranslatorTranslateOptions options = {}
  );

The readable stream at each step will return a Sequence of DOMString.

Activity

  1. toreini commented on Aug 25, 2026

    @toreini
    Collaborator

    Hi @sushraja-msft , Thanks!

    I think this point can be related to #60 . It would be great if you could have a look and if relevant, join the discussions there, especially the performance edge is an interesting discussion with the folks. If yes, then I will close this issue.

    Cheers,
    Ehsan

  2. sushraja-msft commented on Aug 31, 2026

    @sushraja-msft
    Author

    Although there is overlap in developer use case of translating web pages, I do think batching is a separate topic than supporting HTML inputs (for example the batching API can support mime type text/html as input as well once the discussions in #60 resolve).
    Batching, this is purely a way to tune performance as the developer wants for his application.

    • Batching increases throughput in that N translates will complete quicker altogether when batched but it does increase latency for say the first translate in that batch when compared to its latency if it were run without batching.
    • API level support for batching allows developers to separate context, pass content from unrelated elements as separate slots in the batch.
  3. anssiko commented on Sep 3, 2026

    @anssiko
    Member

    RESOLUTION: Draft spec change for batched translation feature. (issue #85)

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions