Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions python/ray/util/state/state_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,13 @@ class A(StateSchema):
for col in cols:
if col in keys:
headers.append(col.upper())

# --- Fix UX Issue #30805: Prepend TASK_ID ---
if "TASK_ID" in headers:
headers.remove("TASK_ID")
headers.insert(0, "TASK_ID")
# ---------------------------------------------
Comment on lines +196 to +200

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.

medium

Modifying the headers list for every single row inside the loop is inefficient, especially when listing a large number of tasks (up to 10,000).

Instead, it is much more efficient to adjust the column order in cols once before entering the loop (around line 185). This avoids redundant list search, removal, and insertion operations for every row in state_data.

You can remove this block inside the loop and place the following logic right after cols = schema.list_columns(detail=detail):

cols = schema.list_columns(detail=detail)
if "task_id" in cols:
    cols.remove("task_id")
    cols.insert(0, "task_id")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Agreed ^^^

The current solution is a bit hacky. Ideally we would define the column order directly in the StateSchema subclass somehow


table.append([data[header.lower()] for header in headers])
return f"""
{header}
Expand Down