Skip to content

Commit 0dce821

Browse files
fix(native): reduce startup probe latency after DA1 (#241)
* fix(native): cut startup probe wait after DA1 reply * fix(native): enforce DA1 drain by elapsed time
1 parent be73751 commit 0dce821

File tree

4 files changed

+51
-3
lines changed

4 files changed

+51
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ The format is based on Keep a Changelog and the project follows Semantic Version
88

99
### Bug Fixes
1010

11+
- **native/detect**: Startup terminal probing now exits after a short DA1 drain window instead of waiting the full 500ms budget when XTVERSION never responds, reducing first-render delay on VTE-like terminals.
1112
- **core/constraints**: Constraint input signatures now include all required runtime dependencies, preventing stale cache reuse when unconstrained referenced widget geometry changes.
1213
- **core/layout**: Constraint resolution now performs bounded in-frame settle passes for deeper parent-dependent chains, eliminating first-frame/resize layout jump artifacts in nested constraint trees.
1314
- **core/layout**: Constraint and scroll override traversal now covers modal/layer slot children (`content`/`actions`) so display and geometry overrides apply consistently to overlay subtrees.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
c0849ae29483322623d4ab564877a8940896affb
1+
97a7b907cc6c5a2886fdaef2ea82c8f9e337013e

packages/native/vendor/zireael/src/core/zr_detect.c

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ enum {
1818
ZR_DETECT_READ_ACCUM_CAP = 4096u,
1919
ZR_DETECT_QUERY_TIMEOUT_MS = 100u,
2020
ZR_DETECT_TOTAL_TIMEOUT_MS = 500u,
21+
ZR_DETECT_DA1_DRAIN_TIMEOUT_MS = 20u,
2122
ZR_DETECT_DECRQM_SET = 1u,
2223
};
2324

@@ -756,6 +757,23 @@ static int32_t zr_detect_read_timeout_slice(uint64_t start_ms, uint32_t spent_ms
756757
return remaining;
757758
}
758759

760+
static int32_t zr_detect_remaining_da1_drain_budget(uint32_t spent_ms) {
761+
if (spent_ms >= (uint32_t)ZR_DETECT_DA1_DRAIN_TIMEOUT_MS) {
762+
return 0;
763+
}
764+
return (int32_t)((uint32_t)ZR_DETECT_DA1_DRAIN_TIMEOUT_MS - spent_ms);
765+
}
766+
767+
static int32_t zr_detect_clamp_timeout_budget(int32_t timeout_ms, int32_t budget_ms) {
768+
if (timeout_ms <= 0 || budget_ms <= 0) {
769+
return 0;
770+
}
771+
if (timeout_ms > budget_ms) {
772+
return budget_ms;
773+
}
774+
return timeout_ms;
775+
}
776+
759777
static zr_terminal_id_t zr_detect_fallback_terminal_id(plat_t* plat) {
760778
zr_terminal_id_t id = ZR_TERM_UNKNOWN;
761779
if (plat_guess_terminal_id(plat, &id) != ZR_OK) {
@@ -847,8 +865,25 @@ zr_result_t zr_detect_probe_terminal(plat_t* plat, const plat_caps_t* baseline_c
847865

848866
uint64_t start_ms = plat_now_ms();
849867
uint32_t timeout_spent_ms = 0u;
868+
/* DA1 acts as a probe sentinel; after it arrives, drain briefly then stop. */
869+
uint8_t da1_responded = 0u;
870+
uint64_t da1_seen_ms = 0u;
871+
uint32_t da1_drain_spent_ms = 0u;
850872
while (true) {
851-
const int32_t timeout_ms = zr_detect_read_timeout_slice(start_ms, timeout_spent_ms);
873+
int32_t timeout_ms = zr_detect_read_timeout_slice(start_ms, timeout_spent_ms);
874+
if (da1_responded != 0u) {
875+
const uint64_t now_ms = plat_now_ms();
876+
uint32_t da1_elapsed_ms = 0u;
877+
if (now_ms > da1_seen_ms) {
878+
const uint64_t delta_ms = now_ms - da1_seen_ms;
879+
da1_elapsed_ms = (delta_ms > UINT32_MAX) ? UINT32_MAX : (uint32_t)delta_ms;
880+
}
881+
if (da1_elapsed_ms > da1_drain_spent_ms) {
882+
da1_drain_spent_ms = da1_elapsed_ms;
883+
}
884+
const int32_t da1_budget_ms = zr_detect_remaining_da1_drain_budget(da1_drain_spent_ms);
885+
timeout_ms = zr_detect_clamp_timeout_budget(timeout_ms, da1_budget_ms);
886+
}
852887
if (timeout_ms <= 0) {
853888
break;
854889
}
@@ -860,6 +895,9 @@ zr_result_t zr_detect_probe_terminal(plat_t* plat, const plat_caps_t* baseline_c
860895
}
861896
if (n == 0) {
862897
timeout_spent_ms += (uint32_t)timeout_ms;
898+
if (da1_responded != 0u) {
899+
da1_drain_spent_ms += (uint32_t)timeout_ms;
900+
}
863901
continue;
864902
}
865903

@@ -871,6 +909,15 @@ zr_result_t zr_detect_probe_terminal(plat_t* plat, const plat_caps_t* baseline_c
871909
memcpy(collected + collected_len, chunk, copy_len);
872910
collected_len += copy_len;
873911
}
912+
if (da1_responded == 0u) {
913+
zr_detect_parsed_t partial;
914+
zr_detect_parsed_reset(&partial);
915+
(void)zr_detect_parse_responses(collected, collected_len, &partial);
916+
da1_responded = partial.da1_responded;
917+
if (da1_responded != 0u) {
918+
da1_seen_ms = plat_now_ms();
919+
}
920+
}
874921
if (collected_len == sizeof(collected)) {
875922
break;
876923
}

0 commit comments

Comments
 (0)