Skip to content

cli: keep packages loaded between batch commands - #28

Open
WiFiGUY512 wants to merge 1 commit into
openwrt:masterfrom
WiFiGUY512:cli-batch-keep-packages-loaded
Open

WiFiGUY512 wants to merge 1 commit into
openwrt:masterfrom
WiFiGUY512:cli-batch-keep-packages-loaded

Conversation

@WiFiGUY512

Copy link
Copy Markdown

uci batch unloaded every loaded package after each command, so the next command loaded its package again: it parsed the config file and replayed the package's whole saved delta, which every set in the batch makes one line longer. A batch of n sets therefore took time quadratic in n or worse.

On an Arista W-118 (IPQ4019), with one section and one option per entry:

Entries Before After
100 0.36 s
500 11.2 s 0.21 s
2000 528 s 1.8 s

Committing the 1000 deltas of 500 entries took 0.06 s of it.

This commit keeps a package loaded after a command that succeeded: the command has saved its changes, and the package in memory is the saved state. It unloads everything:

  • after a command that failed, which may have left a package half changed;
  • before the commands that read a whole package (show, changes, export, commit) or load one themselves (import), so they see what they saw before.

add uses the package when the batch has it loaded already, as uci_load() refuses a loaded one.

Tested on the W-118 with OpenWrt main:

  • The files written by the timing batches above are byte-identical to the stock CLI's.
  • A mixed batch gives the stock CLI's exact output and files. It has add, list add and del_list, rename, reorder, delete, a failing set, revert, show, changes and commit, across two packages.

🤖 Generated with Claude Code

uci batch unloaded every loaded package after each command, so the next
command loaded its package again: it parsed the config file and replayed
the package's whole saved delta, which every set in the batch makes one
line longer. A batch of n sets therefore took time quadratic in n or
worse. On an Arista W-118 (IPQ4019) one section and one option per
entry took 0.36 s for 100 entries, 11 s for 500 and 528 s for 2000;
committing the 1000 deltas of 500 entries took 0.06 s of it.

Keep a package loaded after a command that succeeded: the command has
saved its changes, and the package in memory is the saved state. Unload
everything after a command that failed, which may have left a package
half changed, and before the commands that read a whole package
(show, changes, export, commit) or load one themselves (import), so
they see what they saw before. add uses the package when the batch has
it loaded already, as uci_load() refuses a loaded one.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Christopher Griffin <christophergriffin05@gmail.com>
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