Skip to content

Commit 9d4e4f3

Browse files
committed
workspace(refactor[builder]) route set-option loops through _bulk_set_options
why: Workspace loading dispatches one tmux ``set-option`` per loop iteration across four hot loops (session ``options``, ``global_options``, per-window ``options``, ``options_after``). The helper that ``f4c95faa`` introduced provides a single, batch-shaped entry point for these calls; this commit moves the existing call sites onto it. Today the helper is a plain loop so this is a pure refactor (same N round-trips, same observable behaviour). Once libtmux exposes a pipelined ``Server.batch()`` the helper body can swap internally and the call sites automatically benefit without further changes here. what: - Replace the session ``options`` loop in ``build`` with ``_bulk_set_options(..., scope_flag="-s")`` targeting ``session.session_id``. - Replace the ``global_options`` loop in ``build`` with ``_bulk_set_options(..., target=None, scope_flag="-g")``. - Replace the per-window ``options`` loop in ``iter_create_windows`` with ``_bulk_set_options(..., scope_flag="-w")`` targeting ``window.window_id``. - Replace the ``options_after`` loop in ``_apply_options_after`` (or equivalent post-build hook) with ``_bulk_set_options(..., scope_flag="-w")`` targeting ``window.window_id``. Salvaged from libtmux-protocol@2390ce3b. The original commit described the change as a perf win; against current libtmux 0.56.0 the helper body issues N round-trips per call site (no ``Server.batch()`` yet), so this commit is documented as a refactor and the perf framing is deferred to whenever libtmux ships a batching API.
1 parent 6ccb059 commit 9d4e4f3

1 file changed

Lines changed: 20 additions & 8 deletions

File tree

src/tmuxp/workspace/builder.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -579,12 +579,18 @@ def build(self, session: Session | None = None, append: bool = False) -> None:
579579
self.on_build_event({"event": "before_script_done"})
580580

581581
if "options" in self.session_config:
582-
for option, value in self.session_config["options"].items():
583-
self.session.set_option(option, value)
582+
self._bulk_set_options(
583+
self.session_config["options"],
584+
target=self.session.session_id,
585+
scope_flag="-s",
586+
)
584587

585588
if "global_options" in self.session_config:
586-
for option, value in self.session_config["global_options"].items():
587-
self.session.set_option(option, value, global_=True)
589+
self._bulk_set_options(
590+
self.session_config["global_options"],
591+
target=None,
592+
scope_flag="-g",
593+
)
588594

589595
if "environment" in self.session_config:
590596
for option, value in self.session_config["environment"].items():
@@ -723,8 +729,11 @@ def iter_create_windows(
723729
window_config["options"],
724730
dict,
725731
):
726-
for key, val in window_config["options"].items():
727-
window.set_option(key, val)
732+
self._bulk_set_options(
733+
window_config["options"],
734+
target=window.window_id,
735+
scope_flag="-w",
736+
)
728737

729738
if window_config.get("focus"):
730739
window.select()
@@ -893,8 +902,11 @@ def config_after_window(
893902
window_config["options_after"],
894903
dict,
895904
):
896-
for key, val in window_config["options_after"].items():
897-
window.set_option(key, val)
905+
self._bulk_set_options(
906+
window_config["options_after"],
907+
target=window.window_id,
908+
scope_flag="-w",
909+
)
898910

899911
def find_current_attached_session(self) -> Session:
900912
"""Return current attached session."""

0 commit comments

Comments
 (0)