Skip to content

perf: avoid Pydantic serialization round-trip and cache timezone config#134

Open
xzq-xu wants to merge 1 commit intoHKUDS:mainfrom
xzq-xu:perf/avoid-serialization-roundtrip
Open

perf: avoid Pydantic serialization round-trip and cache timezone config#134
xzq-xu wants to merge 1 commit intoHKUDS:mainfrom
xzq-xu:perf/avoid-serialization-roundtrip

Conversation

@xzq-xu
Copy link
Copy Markdown
Contributor

@xzq-xu xzq-xu commented Apr 13, 2026

Summary

  • collector.py: Replace json.loads(model.model_dump_json(...)) with model.model_dump(mode="json", ...) for tasks and event messages. This eliminates a redundant serialize→string→parse→dict cycle on every task and every message when building the board snapshot.
  • timefmt.py: Cache the configured timezone by config.json file mtime so format_timestamp() only hits disk once per config change instead of on every call. The board renderer formats dozens of timestamps per refresh; this removes repeated load_config() I/O from the hot path while still picking up config edits immediately.

Changes

File What changed
clawteam/board/collector.py json.loads(t.model_dump_json(...))t.model_dump(mode="json", ...) (2 call sites: tasks + messages)
clawteam/timefmt.py Added _get_timezone() with mtime-based cache; format_timestamp() delegates to it

Test plan

  • uv run pytest tests/test_board.py tests/test_timefmt.py -v — 17/17 passed
  • uv run pytest -q — full suite 545 passed, 0 failures
  • uv run ruff check — all checks passed

Made with Cursor

collector.py: replace json.loads(model.model_dump_json(...)) with
model.model_dump(mode="json", ...) for tasks and event messages.
Eliminates a redundant serialize-to-string + parse-back-to-dict cycle
on every task and message in the board snapshot.

timefmt.py: cache the configured timezone by config file mtime so
format_timestamp() only reads ~/.clawteam/config.json once per config
change instead of on every call. The board renderer can format dozens
of timestamps per frame; this removes repeated disk I/O from the hot
path while still picking up config edits immediately.

Made-with: Cursor
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