#messagequeue
📦 bkubicki/declarative-queue 1.0

Explicit, declarative queue arguments for Magento's MessageQueue framework

🔗 https://github.com/bartoszkubicki/declarative-queue
October 11, 2026 at 6:59 PM
Wie man 1.000.000 Benachrichtigungen versendet, ohne abzustürzen

Ein anbieterneutraler System-Design-Durchgang durch die Message-Queue-Architektur, die eine Million Benachrichtigungen versendet, ohne die API lahmzulegen: Fan-out-Worker, Back-P…

#messagequeue #eventdrivenarchitecture #fanout
Wie man 1.000.000 Benachrichtigungen versendet, ohne abzustürzen
Ein anbieterneutraler System-Design-Durchgang durch die Message-Queue-Architektur, die eine Million Benachrichtigungen versendet, ohne die API lahmzulegen: Fan-out-Worker, Back-Pressure, Retries und Dead-Letter-Queues.
www.alekseialeinikov.com
July 13, 2026 at 3:44 AM
How to Send 1,000,000 Notifications Without Falling Over

A vendor-neutral system-design walkthrough of the message-queue architecture that sends a million notifications without taking your API down: fan-out workers, back-pressure, retries, and dea…

#messagequeue #eventdrivenarchitecture #fanout
How to Send 1,000,000 Notifications Without Falling Over
A vendor-neutral system-design walkthrough of the message-queue architecture that sends a million notifications without taking your API down: fan-out workers, back-pressure, retries, and dead-letter queues.
www.alekseialeinikov.com
July 13, 2026 at 3:44 AM
📦 magetips/module-azure v1.0.0

Azure Service Bus integration for Magento's MessageQueue framework, built for Dynamics 365 connectivity.

🔗 https://github.com/mage-tips/azure
July 3, 2026 at 4:21 AM
🚀 SoloEngine v0.3.0 Release — Checkpoint Mechanism & Message Queue
## [v0.3.0] - 2026-06-29 ## 🚀 Added * **Checkpoint Mechanism** — `ReActCore` introduces three checkpoints during streaming: `content_ended` (after text content), `before_tool_calls` (before tool calls), and `after_tool_calls` (after tool calls), enabling precise interception and state synchronization of the execution flow. * **Message Queue System** — Added a new `MessageQueue` class in `run.py`, supporting async enqueue, drain, and remove operations. Users can now queue messages while the LLM is running; queued messages are sent automatically after the current task completes. The frontend introduces a `QueueBar` component to display queued messages, with CSS spinning animation, single-line ellipsis, and hover-to-delete functionality. * **Queue Message Merging** — `MessageQueue.drain_all()` now merges consecutive messages with the same `name` into a single message, preventing fragmented user input when multiple queue entries share the same sender. * **Queue WebSocket Events** — The execution event protocol introduces three new event types: `message_queued`, `queue_drained`, and `queue_returned` (`useRunWebSocket.ts`). The frontend processes queue state updates in real time. * **Stop & Queue Integration** — When the user clicks Stop, pending queued messages are returned to the input box via `queue_returned`. Checkpoint stops cleanly clear the queue and automatically start the next message. * **System Notification Messages** — Introduced the `SystemMessage` type (with `notification` role) to separate error messages from assistant content. Errors are now rendered as independent notification bubbles, no longer embedded within assistant message cards. * **tiktoken Real-Time Token Estimation** — `ReActCore` initializes a `tiktoken` encoder on startup for real-time token counting during streaming. Unknown models fall back to `o200k_base`. ## 🔧 Improved * **Custom Model Name Auto-Complete** — The model name field in `ModelManager` has been upgraded from `Select` to `AutoComplete`, allowing users to type custom model names not in the predefined list. * **Message Block Type Unification** — Added a new `ToolCallsBlock` type (`message_block.py`), unifying the internal tool-call format to an OpenAI-style `tool_calls` list, replacing the legacy `ToolUseBlock`. * **ReActCore Token Accumulation** — Token usage is now estimated chunk-by-chunk via tiktoken and overwritten with the API's precise usage when received. Introduced `_get_valid_token_value` to uniformly handle `None`/0/empty values from the API, preventing placeholder values from overwriting accumulated values. * **ReActCore Streaming Architecture Refactor** — Streaming output structure in `react_core.py` refactored: each `ChatResponse` now contains only a single block type (`SoloTextBlock` or `SoloThinkingBlock`), replacing the previous pattern of accumulating multiple blocks before yielding. This enables the frontend to precisely handle each type of incremental content. * **Message Type Separation** — The frontend message type has been unified from `LLMMessage[]` to `Message[]` (`LLMMessage | SystemMessage`). `convertToLLMMessages` now splits system messages such as `error` into independent `SystemMessage` entries rather than reusing `LLMMessage`. Updated `MessageList` and `RunPanel` to render `SystemMessage` entries. * **Unified Error Save Path** — Normal and error paths in `save_assistant_message` now follow the same code path. `error` is saved as an independent field and no longer written into the data block. * **Execution Completion Reliability** — `on_execution_done` now detects empty-collector scenarios (where `stream_callback` was never triggered) and automatically sets the status to `error` with detailed LLM failure output. This prevents false "completed" status during silent failures. * **Session Creation Flow** — `createNewSession` in `runPanelStore` now immediately inserts the new session into the `sessions` array, ensuring the UI reflects the new session without requiring a refresh. * **Message Input UX** — During LLM execution, the send button stays active to queue new messages instead of showing a blocking warning. The input area supports queuing via WebSocket when `isRunning` or `isWaitingReply` is true. The ENTER key now triggers send (queue) as long as the input has content, no longer blocked by `isRunning` state. * **Assistant Message ID Uniqueness** — Each `execution_start` now generates a new `msg_asst_${Date.now()}` ID, preventing React key conflicts when the queue drain triggers a new assistant message that would otherwise duplicate the previous message ID. * **WebSocket Architecture Refactor** — `websocket_handler.py` has been significantly simplified, removing complex grace period and takeover logic. `RunContext` now owns its own event loop, and the WebSocket only acts as a transport layer with injected callbacks. * **Streaming Cancellation Handling** — When the user clicks the stop button, `aclose()` closing the stream in `ReActCore` no longer raises `CancelledError`; it is treated as a normal end (breaking out of the loop), avoiding misinterpreting expected stream closure as a cancellation error. * **Tool Call Event Management** — `ToolCallEventManager` now uniformly sends tool-call events to the frontend through `tool_calls` blocks, removing the legacy `tool_use` block handling logic. * **Formatter Simplification** — `TruncatedFormatterBase` removed `token_counter` and `max_tokens` parameters along with dead code such as `_truncate` and `_count`; the constructor is simplified to a no-arg empty implementation. `OpenAIChatFormatter` removed the `OpenAIMultiAgentFormatter` subclass. * **Anthropic message_start/message_delta Usage Capture** — `anthropic_model.py` captures `input_tokens` in the `message_start` event and accumulated `output_tokens` in the `message_delta` event, resolving inaccurate token counts in Anthropic streaming responses. * **Anthropic OpenAI Format Conversion** — Added a new `_convert_openai_to_anthropic_messages` static method that converts OpenAI-format messages (`tool_calls`, `reasoning_content`) to Anthropic format (`tool_use`, `thinking`). * **Streaming Tool Call Split** — `anthropic_model.py` and `qwen_model.py` now yield a separate `ChatResponse` for each `tool_call`, enabling precise handling on the frontend. ## 🗑️ Removed * Removed the `backend/SoloAgent/token_counter/` directory, including `__init__.py`, `openai_token_counter.py`, and `token_base.py`. The original functionality has been merged into `ReActCore` inline accumulation. * `backend/SoloAgent/formatter/truncated_formatter_base.py` — removed from the exports in `__init__.py`; the file is preserved but is no longer public API. * Removed dead code `OpenAIMultiAgentFormatter` from `openai_formatter.py`. * `ToolUseBlock` — the message block type was unified from `tool_use` to `tool_calls`; the legacy `tool_use` type is no longer used. * `_convert_anthropic_message_to_solo_format` function — removed a 99-line Anthropic→Solo format conversion function in `anthropic_model.py`, replaced by the new OpenAI→Anthropic conversion method. * **Reasoning_content injection code removed** — Removed the logic that extracts `reasoning_content` from content in `OpenAIChatFormatter`, and removed the compatibility code (with DEBUG logs) that forcibly added an empty `reasoning_content` to messages carrying `tool_calls`. * **Message grouping removed tool_use support** — `TruncatedFormatterBase._group_messages` now only checks `tool_calls` and `tool_result` types, removing `tool_use` compatibility code. ## 🐛 Fixed * **Empty Collector False Report** — Fixed a bug where `agent.reply` caught an exception and returned an error string, but `_execute_agent` treated the run as `completed` because the collector was empty. `on_execution_done` now checks `collector.get_chunk_count() > 0` and forces `status="error"` with the actual LLM error output. * **LLM Tokens Missing on Manual Pause** — Resolved via tiktoken real-time estimation, which serves as a fallback when API usage is unreachable. * **Message Error Display** — Error messages are no longer hidden inside assistant `content` blocks; they are rendered as independent `notification`-role messages with proper styling and status indicators. * **Streaming tool_use Handling** — Fixed the parsing and event-sending logic of legacy `tool_use` blocks in streaming responses, unifying to the `tool_calls` format. * **Filter Thinking-Only Messages in Cache** — `OpenAIChatFormatter` adds filtering logic: when an assistant message has empty `content` and no `tool_calls`, it is skipped. This fixes the LLM API error "Input is a zero-length, empty document". * **ChunkCollector Type Mapping Correction** — `ChunkCollector._extract_raw_type` in `run.py` removed recognition of the `'tool_use'` type string, unifying the mapping to `'tool_calls'`. * **aclose No Longer Raises CancelledError** — `aclose()` closing the stream in `react_core.py` no longer raises `CancelledError`; it breaks out of the loop and is treated as a normal end, avoiding misinterpreting expected stream closure as a cancellation error. * **model._was_cancelled Exception Conversion** — When the model closes the stream due to `aclose` in `react_core.py`, it is no longer converted to `asyncio.CancelledError`; it breaks out of the loop and is treated as a normal end, avoiding misinterpreting expected stream closure as a cancellation error. * **flow_compiler Early Cancellation Detection** — `flow_compiler.py` adds new logic: immediately after creating the flow, check whether `cancel_event` is already set, and if so, cancel the flow right away, avoiding wasted HTTP connections. * **CompiledFlow Interruption Detection** — `flow_compiler.py` fixed a bug where an interrupted Agent incorrectly returned `"completed"`; it now returns `"stop"` status. The `output` field is no longer filled with `error`, preventing error pollution of the output. * **Windows Clipboard Compatibility** — `MessageList.tsx` unifies on the W3C Clipboard API, ensuring that Windows clipboard history (Win+V) is correctly captured; fixed the issue where clipboard history could not be triggered on Windows. ### 🤝 Join Us We're looking for like-minded contributors who share our passion for SoloEngine and Agentic AI. Every contribution — from a typo fix to a full feature — makes SoloEngine better. 📝 Contributing Guide · 💬 Discussions · 📧 Contact Us
dev.to
June 29, 2026 at 3:55 PM
Android Runtimeがアップデート! MessageQueue刷新と世代別GCの真価 | gihyo.jp
Android Runtimeがアップデート! MessageQueue刷新と世代別GCの真価 | gihyo.jp
2026年も4月に入り、Google I/Oの足音が近づいてきました。今週は、開発者版の検証を通じて明らかになった、Android 17で「ART(Android Runtime)」が大幅に進化しているので、今回はこれにフォーカスします。
gihyo.jp
April 16, 2026 at 1:14 AM
Android Weekly Topics「Android Runtimeがアップデート! MessageQueue刷新と世代別GCの真価」公開
gihyo.jp/article/2026...
Android Runtimeがアップデート! MessageQueue刷新と世代別GCの真価 | gihyo.jp
2026年も4月に入り、Google I/Oの足音が近づいてきました。今週は、開発者版の検証を通じて明らかになった、Android 17で「ART(Android Runtime)」が大幅に進化しているので、今回はこれにフォーカスします。
gihyo.jp
April 16, 2026 at 12:36 AM
Android OS Architecture, Part 8: Handlers and System Services Explained

This article explains two core Android concepts: Handlers and System Services. Handlers manage thread communication by posting tasks to a Looper’s MessageQueue, enabling safe UI updates from background thread…
#hackernews #news
Android OS Architecture, Part 8: Handlers and System Services Explained
This article explains two core Android concepts: Handlers and System Services. Handlers manage thread communication by posting tasks to a Looper’s MessageQueue, enabling safe UI updates from background threads. System Services, on the other hand, act as secure intermediaries between apps and device hardware, using IPC through the System Server. Together, they illustrate how Android coordinates work across threads and processes while maintaining performance and security.
hackernoon.com
March 30, 2026 at 4:19 PM
Learn how Android’s Looper and MessageQueue keep the main thread alive, process events, and cause subtle UI bugs—with a practical code example. #androidappdevelopment
Android OS Architecture, Part 7: Inside the Main Thread, Looper and MessageQueue
hackernoon.com
March 23, 2026 at 8:26 AM
Learn about #MessageQueue integration with RabbitMQ and MassTransit in .NET! This guide breaks down the essentials, helping you streamline asynchronous tasks in your application. Dive into scalable architecture! #DotNet
Just a moment...
medium.com
March 8, 2026 at 9:15 PM
ロックダウン時代:Android 17は妥協のないセキュリティ要件を備えたアプリの規則を書き換える

Android 17は、このOSの新しいバージョンを対象とするアプリケーションの運用パラダイムを根本的に書き換えています。この包括的なアップデートはデバイスセキュリティを大幅に強化し、開発者が以前のリリースで慣れていた多くの自由を積極的に廃止しています。厳密な修正がない場合、特定のプログラムは顕著な不安定性を示すことになります。…
ロックダウン時代:Android 17は妥協のないセキュリティ要件を備えたアプリの規則を書き換える
Android 17は、このOSの新しいバージョンを対象とするアプリケーションの運用パラダイムを根本的に書き換えています。この包括的なアップデートはデバイスセキュリティを大幅に強化し、開発者が以前のリリースで慣れていた多くの自由を積極的に廃止しています。厳密な修正がない場合、特定のプログラムは顕著な不安定性を示すことになります。 このシステムはMessageQueueの完全に再考された実装を備えています。その結果、タスク実行は前例のない速さを達成し、ユーザーインターフェイスがフレームをドロップすることはまれです。それでも、以前は秘密の内部方法論に頼っていたアプリケーションは、Googleが承認されていない回避策のサポートを体系的に排除しているため、システムエラーに遭遇する危険性があります。 しかし、最も深刻な変換はセキュリティの領域にあります。Android 17は、バックグラウンドからインターフェーススクリーンを起動する機能を大幅に制限しています。アプリケーションはアクティブなプロセスの上に任意にウィンドウを召喚することを許可されなくなりました。システムは今、そのような操作のためにはるかに厳しい前提条件を要求しています。この強力な保護措置は、フィッシング行為と悪意のあるインターフェース詐称を阻止するために細心の注意を払って設計されています。 さらに、USE_LOOPBACK_INTERFACEという新しいパーミッションが導入されました。歴史的に、標準的なインターネットアクセスを持つアプリケーションは、127.0.0.1などのローカルアドレスを介してデータを容易に交換することができました。今後、異なるアプリケーションまたはユーザープロフィール間の通信には、明示的な相互同意が必要になります。このパーミッションが宣言されていない場合、接続は明確に拒否されます。逆に、ローカルアドレスを横切るアプリケーション内トラフィックは完全に妨げられません。 さらに、Certificate Transparencyの検証はすべての新しいアプリケーションで自動的にアクティブ化されています。オペレーティングシステムはデジタル証明書の真正性と利用を細心の注意を払って監視し、開発者からの追加の設定を要求しません。 コード読み込みプロトコルは同等の厳しさに従っています。アプリケーションが外部ライブラリを呼び出そうとするたびに、オペレーティングシステムは現在、そのようなファイルが厳密に読み取り専用のステータスを持つことを不変に要求しています。このプロトコルからの逸脱は、読み込みシーケンスの完全なブロックをもたらします。 画面が広がったデバイスでは、Android 17は向きとウィンドウサイズ制約を厚かましく無視したアプリケーションに以前与えられていた寛容さを決定的に廃止しています。ソフトウェアは現在、多様な画面構成にわたって完璧な優雅さで実行する必要があります。 最終的に、Android 17は、無限の開発者の寛容さの時代が終わったことの決定的な証拠となります。プラットフォームは現在、妥協のないセキュリティと安定性を果てしなく追求する際に、妥協のない厳密さで建築上の要件を指示しています。これらの新しい指示を無視することは、避けられない明白な悪影響を招くことです。 翻訳元:
blackhatnews.tokyo
March 3, 2026 at 4:57 AM
今週のAndroid Weekly(Dagashiでも取り上げられていた)Android17のMessageQueueのロックフリー話が良かった。

一瞬Androidのアプリ間の話でActivityManagerServiceとかZygoteプロセス周りの話かと思ったけどアプリ内のLooperとThreadの話で、並行性向上だけでなくCPUの分岐予測まで踏み込んだ最適化の話があるのが面白かった。

android-developers.googleblog.com/2026/02/unde...
Under the hood: Android 17’s lock-free MessageQueue
News and insights on the Android platform, developer tools, and events.
android-developers.googleblog.com
February 23, 2026 at 6:11 AM
What an interesting read!
android-developers.googleblog.com/2026/02/unde...
I wonder, though, why it took them so long to realize the optimization opportunity.
Under the hood: Android 17’s lock-free MessageQueue
News and insights on the Android platform, developer tools, and events.
android-developers.googleblog.com
February 22, 2026 at 9:10 PM
一週間の Android 開発関連ニュースをお届けする AndroidDagashi、第416回を公開しました!

Android17 Beta1:常設Canary/大画面適応必須,A17大画面:回転固定/リサイズ拒否無効,MessageQueueロックフリー,CIボトルネックはI/O,SnapshotStateList罠, など

https://androiddagashi.github.io/issue/416-2026-02-22
416 2026-02-22
Android17 Beta1:常設Canary/大画面適応必須,A17大画面:回転固定/リサイズ拒否無効,MessageQueueロックフリー,CIボトルネックはI/O,SnapshotStateList罠, など
androiddagashi.github.io
February 22, 2026 at 11:13 AM
Google впроваджує в Android 17 планувальник на рівні системи під назвою DeliQueue, щоб скоротити час очікування ядра та зменшити затримки в роботі інтерфейсу користувача. Ця зміна може зробити щоденну взаємодію з телефоном плавнішою #Android17 #Google #DeliQueue
gizchina.net/2026/02/20/a...
Android 17 з DeliQueue зменшить падіння кадрів і зробить інтерфейс плавнішим
Google впроваджує в Android 17 системний інструмент DeliQueue, який переробляє роботу MessageQueue, зменшує лаги та стутер, скорочує пропуски кадрів (drop frames) і робить інтерфейс плавнішим — перші тести показують до 7.7% зниження на головному екрані.
gizchina.net
February 20, 2026 at 8:19 PM
I'm always fascinated by lock-free algorithms. This optimization for Android is really impressive and complex. And then they even added branch-free programming to speed it up even more! android-developers.googleblog.com/2026/02/unde...
Under the hood: Android 17’s lock-free MessageQueue
News and insights on the Android platform, developer tools, and events.
android-developers.googleblog.com
February 20, 2026 at 1:12 AM
Android 17 riduce i lag: come cambia la gestione dei frame
Android 17 introduce DeliQueue, una nuova gestione lock-free della MessageQueue che riduce i frame persi...
https://www.ilsoftware.it/android-17-riduce-i-lag-come-cambia-la-gestione-dei-frame/
February 19, 2026 at 11:00 AM
Android 17 è più fluido: Google introduce la nuova architettura DeliQueue
#Android #android17 #DeliQueue #google #MessageQueue #schermo
🔗 https://guruhitech.com/android-17-e-piu-fluido-google-introduce-la-nuova-architettura-deliqueue/
February 18, 2026 at 3:59 PM
whoa, they completely rewrote MessageQueue to be lock-free!

This is an extremely important part of the Android system lib used by Handler, Looper, etc.

android-developers.googleblog.com/2026/02/unde...
Under the hood: Android 17’s lock-free MessageQueue
News and insights on the Android platform, developer tools, and events.
android-developers.googleblog.com
February 18, 2026 at 1:53 PM
Android 17's lock-free MessageQueue Article URL: https://android-developers.googleblog.com/2026/02/under-hood-android-17s-lock-free.html Comments URL: https://news.ycombinator.com/item?id=47058...

Origin | Interest | Match
Under the hood: Android 17’s lock-free MessageQueue
_Posted by Shai Barack, Android Platform Performance Lead and Charles Munger, Principal Software Engineer_ In Android 17, apps targeting SDK 37 or higher will receive a new implementation of MessageQueue where the implementation is lock-free. The new implementation improves performance and reduces missed frames, but may break clients that reflect on MessageQueue private fields and methods. To learn more about the behavior change and how you can mitigate impact, check out the MessageQueue behavior change documentation. This technical blog post provides an overview of the MessageQueue rearchitecture and how you can analyze lock contention issues using Perfetto. The Looper drives the UI thread of every Android application. It pulls work from a MessageQueue, dispatches it to a Handler, and repeats. For two decades, MessageQueue used a single monitor lock (i.e. a synchronized code block) to protect its state. Android 17 introduces a significant update to this component: a lock-free implementation named DeliQueue. This post explains how locks affect UI performance, how to analyze these issues with Perfetto, and the specific algorithms and optimizations used to improve the Android main thread. The problem: Lock Contention and Priority Inversion The legacy MessageQueue functioned as a priority queue protected by a single lock. If a background thread posts a message while the main thread performs queue maintenance, the background thread blocks the main thread. When two or more threads are competing for exclusive use of the same lock, this is called Lock contention. This contention can cause Priority Inversion, leading to UI jank and other performance problems. Priority inversion can happen when a high-priority thread (like the UI thread) is made to wait for a low-priority thread. Consider this sequence: 1. A low priority background thread acquires the MessageQueue lock to post the result of work that it did. 2. A medium priority thread becomes runnable and the Kernel's scheduler allocates it CPU time, preempting the low priority thread. 3. The high priority UI thread finishes its current task and attempts to read from the queue, but is blocked because the low priority thread holds the lock. The low-priority thread blocks the UI thread, and the medium-priority work delays it further. Analyzing contention with Perfetto You can diagnose these issues using Perfetto. In a standard trace, a thread blocked on a monitor lock enters the sleeping state, and Perfetto shows a slice indicating the lock owner. When you query trace data, look for slices named “monitor contention with …” followed by the name of the thread that owns the lock and the code site where the lock was acquired. Case study: Launcher jank To illustrate, let’s analyze a trace where a user experienced jank while navigating home on a Pixel phone immediately after taking a photo in the camera app. Below we see a screenshot of Perfetto showing the events leading up to the missed frame: * Symptom: The Launcher main thread missed its frame deadline. It blocked for 18ms, which exceeds the 16ms deadline required for 60Hz rendering. * Diagnosis: Perfetto showed the main thread blocked on the MessageQueue lock. A “BackgroundExecutor” thread owned the lock. * Root Cause: The BackgroundExecutor runs at Process.THREAD_PRIORITY_BACKGROUND (very low priority). It performed a non-urgent task (checking app usage limits). Simultaneously, medium priority threads were using CPU time to process data from the camera. The OS scheduler preempted the BackgroundExecutor thread to run the camera threads. This sequence caused the Launcher’s UI thread (high priority) to become indirectly blocked by the camera worker thread (medium priority), which was keeping the Launcher’s background thread (low priority) from releasing the lock. Querying traces with PerfettoSQL You can use PerfettoSQL to query trace data for specific patterns. This is useful if you have a large bank of traces from user devices or tests, and you’re searching for specific traces that demonstrate a problem. For example, this query finds MessageQueue contention coincident with dropped frames (jank): INCLUDE PERFETTO MODULE android.monitor_contention; INCLUDE PERFETTO MODULE android.frames.jank_type; SELECT process_name, -- Convert duration from nanoseconds to milliseconds SUM(dur) / 1000000 AS sum_dur_ms, COUNT(*) AS count_contention FROM android_monitor_contention WHERE is_blocked_thread_main AND short_blocked_method LIKE "%MessageQueue%" -- Only look at app processes that had jank AND upid IN ( SELECT DISTINCT(upid) FROM actual_frame_timeline_slice WHERE android_is_app_jank_type(jank_type) = TRUE ) GROUP BY process_name ORDER BY SUM(dur) DESC; In this more complex examples, join trace data that spans multiple tables to identify MessageQueue contention during app startup: INCLUDE PERFETTO MODULE android.monitor_contention; INCLUDE PERFETTO MODULE android.startup.startups; -- Join package and process information for startups DROP VIEW IF EXISTS startups; CREATE VIEW startups AS SELECT startup_id, ts, dur, upid FROM android_startups JOIN android_startup_processes USING(startup_id); -- Intersect monitor contention with startups in the same process. DROP TABLE IF EXISTS monitor_contention_during_startup; CREATE VIRTUAL TABLE monitor_contention_during_startup USING SPAN_JOIN(android_monitor_contention PARTITIONED upid, startups PARTITIONED upid); SELECT process_name, SUM(dur) / 1000000 AS sum_dur_ms, COUNT(*) AS count_contention FROM monitor_contention_during_startup WHERE is_blocked_thread_main AND short_blocked_method LIKE "%MessageQueue%" GROUP BY process_name ORDER BY SUM(dur) DESC; You can use your favorite LLM to write PerfettoSQL queries to find other patterns. At Google, we use BigTrace to run PerfettoSQL queries across millions of traces. In doing so, we confirmed that what we saw anecdotally was, in fact, a systemic issue. The data revealed that MessageQueue lock contention impacts users across the entire ecosystem, substantiating the need for a fundamental architectural change. Solution: lock-free concurrency We addressed the MessageQueue contention problem by implementing a lock-free data structure, using atomic memory operations rather than exclusive locks to synchronize access to shared state. A data structure or algorithm is lock-free if at least one thread can always make progress regardless of the scheduling behavior of the other threads. This property is generally hard to achieve, and is usually not worth pursuing for most code. The atomic primitives Lock-free software often relies on atomic Read-Modify-Write primitives that the hardware provides. On older generation ARM64 CPUs, atomics used a Load-Link/Store-Conditional (LL/SC) loop. The CPU loads a value and marks the address. If another thread writes to that address, the store fails, and the loop retries. Because the threads can keep trying and succeed without waiting for another thread, this operation is lock-free. ARM64 LL/SC loop example retry: ldxr x0, [x1] // Load exclusive from address x1 to x0 add x0, x0, #1 // Increment value by 1 stxr w2, x0, [x1] // Store exclusive. // w2 gets 0 on success, 1 on failure cbnz w2, retry // If w2 is non-zero (failed), branch to retr (view in Compiler Explorer) Newer ARM architectures (ARMv8.1) support Large System Extensions (LSE) which include instructions in the form of Compare-And-Swap (CAS) or Load-And-Add (demonstrated below). In Android 17 we added support to the Android Runtime (ART) compiler to detect when LSE is supported and emit optimized instructions: / ARMv8.1 LSE atomic example ldadd x0, x1, [x2] // Atomic load-add. // Faster, no loop required. In our benchmarks, high-contention code that uses CAS achieves a ~3x speedup over the LL/SC variant. The Java programming language offers atomic primitives via java.util.concurrent.atomic that rely on these and other specialized CPU instructions. The Data Structure: DeliQueue To remove lock contention from MessageQueue, our engineers designed a novel data structure called DeliQueue. DeliQueue separates Message insertion from Message processing: 1. The list of Messages (Treiber stack): A lock-free stack. Any thread can push new Messages here without contention. 2. The priority queue (Min-heap): A heap of Messages to handle, exclusively owned by the Looper thread (hence no synchronization or locks are needed to access). ### Enqueue: pushing to a Treiber stack The list of Messages is kept in a Treiber stack [1], a lock-free stack that uses a CAS loop to update the head pointer. public class TreiberStack <E> { AtomicReference<Node<E>> top = new AtomicReference<Node<E>>(); public void push(E item) { Node<E> newHead = new Node<E>(item); Node<E> oldHead; do { oldHead = top.get(); newHead.next = oldHead; } while (!top.compareAndSet(oldHead, newHead)); } public E pop() { Node<E> oldHead; Node<E> newHead; do { oldHead = top.get(); if (oldHead == null) return null; newHead = oldHead.next; } while (!top.compareAndSet(oldHead, newHead)); return oldHead.item; } } Source code based on Java Concurrency in Practice [2], available online and released to the public domain Any producer can push new Messages to the stack at any time. This is like pulling a ticket at a deli counter - your number is determined by when you showed up, but the order you get your food in doesn't have to match. Because it's a linked stack, every Message is a sub-stack - you can see what the Message queue was like at any point in time by tracking the head and iterating forwards - you won't see any new Messages pushed on top, even if they're being added during your traversal. ### Dequeue: bulk transfer to a min-heap To find the next Message to handle, the Looper processes new Messages from the Treiber stack by walking the stack starting from the top and iterating until it finds the last Message that it previously processed. As the Looper traverses down the stack, it inserts Messages into the deadline-ordered min-heap. Since the Looper exclusively owns the heap, it orders and processes Messages without locks or atomics. In walking down the stack, the Looper also creates links from stacked Messages back to their predecessors, thus forming a doubly-linked list. Creating the linked list is safe because links pointing down the stack are added via the Treiber stack algorithm with CAS, and links up the stack are only ever read and modified by the Looper thread. These back links are then used to remove Messages from arbitrary points in the stack in O(1) time. This design provides _O_(1) insertion for producers (threads posting work to the queue) and amortized _O_(log N) processing for the consumer (the Looper). Using a min-heap to order Messages also addresses a fundamental flaw in the legacy MessageQueue, where Messages were kept in a singly-linked list (rooted at the top). In the legacy implementation, removal from the head was _O_(1), but insertion had a worst case of _O(N)_ – scaling poorly for overloaded queues! Conversely, insertion to and removal from the min-heap scale logarithmically, delivering competitive average performance but really excelling in tail latencies. | Legacy (locked) MessageQueue| DeliQueue ---|---|--- Insert| _O(N)_| _O_(1) for calling thread _O(logN)_ for Looper thread Remove from head| _O_(1)| _O(logN)_ In the legacy queue implementation, producers and the consumer used a lock to coordinate exclusive access to the underlying singly-linked list. In DeliQueue, the Treiber stack handles concurrent access, and the single consumer handles ordering its work queue. Removal: consistency via tombstones DeliQueue is a hybrid data structure, joining a lock-free Treiber stack with a single-threaded min-heap. Keeping these two structures in sync without a global lock presents a unique challenge: a message might be physically present in the stack but logically removed from the queue. To solve this, DeliQueue uses a technique called “tombstoning.” Each Message tracks its position in the stack via the backwards and forwards pointers, its index in the heap’s array, and a boolean flag indicating whether it has been removed. When a Message is ready to run, the Looper thread will CAS its removed flag, then remove it from the heap and stack. When another thread needs to remove a Message, it doesn't immediately extract it from the data structure. Instead, it performs the following steps: 1. Logical removal: the thread uses a CAS to atomically set the Message’s removal flag from false to true. The Message remains in the data structure as evidence of its pending removal, a so-called “tombstone”. Once a Message is flagged for removal, DeliQueue treats it as if it no longer exists in the queue whenever it’s found. 2. Deferred cleanup: The actual removal from the data structure is the responsibility of the Looper thread, and is deferred until later. Rather than modifying the stack or heap, the remover thread adds the Message to another lock-free freelist stack. 3. Structural removal: Only the Looper can interact with the heap or remove elements from the stack. When it wakes up, it clears the freelist and processes the Messages it contained. Each Message is then unlinked from the stack and removed from the heap. This approach keeps all management of the heap single-threaded. It minimizes the number of concurrent operations and memory barriers required, making the critical path faster and simpler. ### Traversal: benign Java memory model data races Most concurrency APIs, such as Future in the Java standard library, or Kotlin’s Job and Deferred, include a mechanism to cancel work before it completes. An instance of one of these classes matches 1:1 with a unit of underlying work, and calling cancel on an object cancels the specific operations associated with them. Today’s Android devices have multi-core CPUs and concurrent, generational garbage collection. But when Android was first developed, it was too expensive to allocate one object for each unit of work. Consequently, Android’s Handler supports cancellation via numerous overloads of removeMessages - rather than removing a specific Message, it removes all Messages that match the specified criteria. In practice, this requires iterating through all Messages inserted before removeMessages was called and removing the ones that match. When iterating forward, a thread only requires one ordered atomic operation, to read the current head of the stack. After that, ordinary field reads are used to find the next Message. If the Looper thread modifies the next fields while removing Messages, the Looper’s write and another thread’s read are unsynchronized - this is a data race. Normally, a data race is a serious bug that can cause huge problems in your app - leaks, infinite loops, crashes, freezes, and more. However, under certain narrow conditions, data races can be benign within the Java Memory Model. Suppose we start with a stack of: We perform an atomic read of the head, and see A. A’s next pointer points to B. At the same time as we process B, the looper might remove B and C, by updating A to point to C and then D. Even though B and C are logically removed, B retains its next pointer to C, and C to D. The reading thread continues traversing through the detached removed nodes and eventually rejoins the live stack at D. By designing DeliQueue to handle races between traversal and removal, we allow for safe, lock-free iteration. Quitting: Native refcount Looper is backed by a native allocation that must be manually freed once the Looper has quit. If some other thread is adding Messages while the Looper is quitting, it could use the native allocation after it’s freed, a memory safety violation. We prevent this using a tagged refcount, where one bit of the atomic is used to indicate whether the Looper is quitting. Before using the native allocation, a thread reads the refcount atomic. If the quitting bit is set, it returns that the Looper is quitting and the native allocation must not be used. If not, it attempts a CAS to increment the number of active threads using the native allocation. After doing what it needs to, it decrements the count. If the quitting bit was set after its increment but before the decrement, and the count is now zero, then it wakes up the Looper thread. When the Looper thread is ready to quit, it uses CAS to set the quitting bit in the atomic. If the refcount was 0, it can proceed to free its native allocation. Otherwise, it parks itself, knowing that it will be woken up when the last user of the native allocation decrements the refcount. This approach does mean that the Looper thread waits for the progress of other threads, but only when it’s quitting. That only happens once and is not performance sensitive, and it keeps the other code for using the native allocation fully lock-free. There’s a lot of other tricks and complexity in the implementation. You can learn more about DeliQueue by reviewing the source code. Optimization: branchless programming While developing and testing DeliQueue, the team ran many benchmarks and carefully profiled the new code. One issue identified using the simpleperf tool was pipeline flushes caused by the Message comparator code. A standard comparator uses conditional jumps, with the condition for deciding which Message comes first simplified below: static int compareMessages(@NonNull Message m1, @NonNull Message m2) { if (m1 == m2) { return 0; } // Primary queue order is by when. // Messages with an earlier when should come first in the queue. final long whenDiff = m1.when - m2.when; if (whenDiff > 0) return 1; if (whenDiff < 0) return -1; // Secondary queue order is by insert sequence. // If two messages were inserted with the same `when`, the one inserted // first should come first in the queue. final long insertSeqDiff = m1.insertSeq - m2.insertSeq; if (insertSeqDiff > 0) return 1; if (insertSeqDiff < 0) return -1; return 0; } This code compiles to conditional jumps (b.le and cbnz instructions). When the CPU encounters a conditional branch, it can’t know whether the branch is taken until the condition is computed, so it doesn’t know which instruction to read next, and has to guess, using a technique called branch prediction. In a case like binary search, the branch direction will be unpredictably different at each step, so it’s likely that half the predictions will be wrong. Branch prediction is often ineffective in searching and sorting algorithms (such as the one used in a min-heap), because the cost of guessing wrong is larger than the improvement from guessing correctly. When the branch predictor guesses wrong, it must throw away the work it did after assuming the predicted value, and start again from the path that was actually taken - this is called a pipeline flush. To find this issue, we profiled our benchmarks using the branch-misses performance counter, which records stack traces where the branch predictor guesses wrong. We then visualized the results with Google pprof, as shown below: Recall that the original MessageQueue code used a singly-linked list for the ordered queue. Insertion would traverse the list in sorted order as a linear search, stopping at the first element that’s past the point of insertion and linking the new Message ahead of it. Removal from the head simply required unlinking the head. Whereas DeliQueue uses a min-heap, where mutations require reordering some elements (sifting up or down) with logarithmic complexity in a balanced data structure, where any comparison has an even chance of directing the traversal to a left child or to a right child. The new algorithm is asymptotically faster, but exposes a new bottleneck as the search code stalls on branch misses half the time. Realizing that branch misses were slowing down our heap code, we optimized the code using branch-free programming: // Branchless Logic static int compareMessages(@NonNull Message m1, @NonNull Message m2) { final long when1 = m1.when; final long when2 = m2.when; final long insertSeq1 = m1.insertSeq; final long insertSeq2 = m2.insertSeq; // signum returns the sign (-1, 0, 1) of the argument, // and is implemented as pure arithmetic: // ((num >> 63) | (-num >>> 63)) final int whenSign = Long.signum(when1 - when2); final int insertSeqSign = Long.signum(insertSeq1 - insertSeq2); // whenSign takes precedence over insertSeqSign, // so the formula below is such that insertSeqSign only matters // as a tie-breaker if whenSign is 0. return whenSign * 2 + insertSeqSign; } To understand the optimization, disassemble the two examples in Compiler Explorer and use LLVM-MCA, a CPU simulator that can generate an estimated timeline of CPU cycles. The original code: Index 01234567890123 [0,0] DeER . . . sub x0, x2, x3 [0,1] D=eER. . . cmp x0, #0 [0,2] D==eER . . cset w0, ne [0,3] .D==eER . . cneg w0, w0, lt [0,4] .D===eER . . cmp w0, #0 [0,5] .D====eER . . b.le #12 [0,6] . DeE---R . . mov w1, #1 [0,7] . DeE---R . . b #48 [0,8] . D==eE-R . . tbz w0, #31, #12 [0,9] . DeE--R . . mov w1, #-1 [0,10] . DeE--R . . b #36 [0,11] . D=eE-R . . sub x0, x4, x5 [0,12] . D=eER . . cmp x0, #0 [0,13] . D==eER. . cset w0, ne [0,14] . D===eER . cneg w0, w0, lt [0,15] . D===eER . cmp w0, #0 [0,16] . D====eER. csetm w1, lt [0,17] . D===eE-R. cmp w0, #0 [0,18] . .D===eER. csinc w1, w1, wzr, le [0,19] . .D====eER mov x0, x1 [0,20] . .DeE----R ret Note the one conditional branch, b.le,  which avoids comparing the insertSeq fields if the result is already known from comparing the when fields. The branchless code: Index 012345678 [0,0] DeER . . sub x0, x2, x3 [0,1] DeER . . sub x1, x4, x5 [0,2] D=eER. . cmp x0, #0 [0,3] .D=eER . cset w0, ne [0,4] .D==eER . cneg w0, w0, lt [0,5] .DeE--R . cmp x1, #0 [0,6] . DeE-R . cset w1, ne [0,7] . D=eER . cneg w1, w1, lt [0,8] . D==eeER add w0, w1, w0, lsl #1 [0,9] . DeE--R ret Here, the branchless implementation takes fewer cycles and instructions than even the shortest path through the branchy code - it’s better in all cases. The faster implementation plus the elimination of mispredicted branches resulted in a 5x improvement in some of our benchmarks! However, this technique is not always applicable. Branchless approaches generally require doing work that will be thrown away, and if the branch is predictable most of the time, that wasted work can slow your code down. In addition, removing a branch often introduces a data dependency. Modern CPUs execute multiple operations per cycle, but they can’t execute an instruction until its inputs from a previous instruction are ready. In contrast, a CPU can speculate about data in branches, and work ahead if a branch is predicted correctly. ## Testing and Validation Validating the correctness of lock-free algorithms is notoriously difficult! In addition to standard unit tests for continuous validation during development, we also wrote rigorous stress tests to verify queue invariants and to attempt to induce data races if they existed. In our test labs we could run millions of test instances on emulated devices and on real hardware. With Java ThreadSanitizer (JTSan) instrumentation, we could use the same tests to also detect some data races in our code. JTSan did not find any problematic data races in DeliQueue, but - surprisingly -actually detected two concurrency bugs in the Robolectric framework, which we promptly fixed. To improve our debugging capabilities, we built new analysis tools. Below is an example showing an issue in Android platform code where one thread is overloading another thread with Messages, causing a large backlog, visible in Perfetto thanks to the MessageQueue instrumentation feature that we added. To enable MessageQueue tracing in the system_server process, include the following in your Perfetto configuration: data_sources { config { name: "track_event" target_buffer: 0 # Change this per your buffers configuration track_event_config { enabled_categories: "mq" } } } Impact DeliQueue improves system and app performance by eliminating locks from MessageQueue. * Synthetic benchmarks: multi-threaded insertions into busy queues is up to 5,000x faster than the legacy MessageQueue, thanks to improved concurrency (the Treiber stack) and faster insertions (the min-heap). * In Perfetto traces acquired from internal beta testers, we see a reduction of 15% in app main thread time spent in lock contention. * On the same test devices, the reduced lock contention leads to significant improvements to the user experience, such as: * -4% missed frames in apps. * -7.7% missed frames in System UI and Launcher interactions. * -9.1% in time from app startup to the first frame drawn, at the 95%ile. ## Next steps DeliQueue is rolling out to apps in Android 17. App developers should review preparing your app for the new lock-free MessageQueue on the Android Developers blog to learn how to test their apps. ## References [1] Treiber, R.K., 1986. Systems programming: Coping with parallelism. International Business Machines Incorporated, Thomas J. Watson Research Center. [2] Goetz, B., Peierls, T., Bloch, J., Bowbeer, J., Holmes, D., & Lea, D. (2006). Java Concurrency in Practice. Addison-Wesley Professional.
android-developers.googleblog.com
February 18, 2026 at 9:10 AM
Google разкри как ще направи всички смартфони да работят по-плавно с Android 17

В бета-версията на Android 17, Google добави фундаментална промяна в начина, по който се обработват системните задачи, правейки превъртането и анимациите забележимо по-плавни. Инженерите преработиха един от най-старите…
Google разкри как ще направи всички смартфони да работят по-плавно с Android 17
В бета-версията на Android 17, Google добави фундаментална промяна в начина, по който се обработват системните задачи, правейки превъртането и анимациите забележимо по-плавни. Инженерите преработиха един от най-старите компоненти на операционната система, за да елиминират забавянето и закъснението при голямо натоварване. Според Android Authority, основната промяна се отнася до подсистемата MessageQueue, която управлява опашката от съобщения за рендиране на потребителския интерфейс. Преди това, потокът от програмен код можеше временно да блокира тази опашка, принуждавайки други нишки да чакат за достъп. Дългите забавяния пречеха на важните процеси да завършат навреме, което водеше до пропуснати кадри и забележимо забиване.
www.kaldata.com
February 18, 2026 at 8:05 AM
Google is removing this global lock that means threads can use the MessageQueue without blocking each other

And you will get lag free experience
February 18, 2026 at 7:25 AM
displays the UI updates

Whenever the system needs to update the screen - like when you scroll - the UI thread reads task from this MessageQueue

The Problem:

Old Message Queue used a global lock

When different threads (UI thread + Background thread) tried to access
February 18, 2026 at 7:25 AM