CP-314128: Reduce unnecessary allocations and complexity across xapi - #7240
Open
GabrielBuica wants to merge 8 commits into
Open
CP-314128: Reduce unnecessary allocations and complexity across xapi#7240GabrielBuica wants to merge 8 commits into
GabrielBuica wants to merge 8 commits into
Conversation
In check_operation_error, metrics was fetched via Db.VM.get_metrics when vmr.Db_actions.vM_metrics already held the same value. Similarly, Db.VM.get_by_uuid looked up the VM ref we already have as a parameter. Eliminating these two extra DB calls avoids unnecessary overhead on a function that is invoked for every VM allowed-operations recomputation. Signed-off-by: Gabriel Buica <danutgabriel.buica@citrix.com>
GabrielBuica
force-pushed
the
private/dbuica/CP-314128
branch
from
August 26, 2026 13:23
5010842 to
404af73
Compare
psafont
reviewed
Aug 26, 2026
last-genius
approved these changes
Aug 27, 2026
added 7 commits
August 27, 2026 15:59
get_since_for_events reversed the entire 512-entry in_memory_cache list just to peek at the oldest (last) element. Replace with Listext.List.last which traverses without allocating a reversed copy. Signed-off-by: Gabriel Buica <danutgabriel.buica@citrix.com>
The 'replacing' pattern was recompiled via Re.Str.regexp on every line of yum upgrade output. Move it to module level so it is compiled once. Regex compilation is more expensive than matching, so recompiling on every line is unnecessary repeated work. Signed-off-by: Gabriel Buica <danutgabriel.buica@citrix.com>
host_of_vm called Db.VM.get_record to fetch the entire VM record but only used scheduled_to_be_resident_on, resident_on, and power_state. Replace with three individual field getters. get_record deserialises every field of the VM object. Using targeted getters avoids that overhead, which matters when iterating over all VMs in a group for anti-affinity placement. Signed-off-by: Gabriel Buica <danutgabriel.buica@citrix.com>
stats_get and stats_diff_get used List.nth for O(n) indexed access on every field of every VDI during each sampling cycle. Convert the stats lists to arrays once, then index with O(1) array access. This function runs on every RRD sampling tick for every VDI, so replacing O(n) list traversals with O(1) array lookups reduces per-tick overhead. Signed-off-by: Gabriel Buica <danutgabriel.buica@citrix.com>
parse_single_line in config_sriov compiled two regexes on every line of the modprobe config: a driver-specific pattern and a whitespace splitter. Move the driver pattern before the loop and the whitespace splitter to module level so both are compiled once. Re.Perl.compile_pat is more expensive than matching. Even though modprobe config files are short, recompiling on every line is unnecessary. Signed-off-by: Gabriel Buica <danutgabriel.buica@citrix.com>
get_updates_from_updateinfo and get_updates_from_repoquery both filtered available packages against known updates using List.mem, giving O(A*U) per-element membership tests. Build a Set from the updates list first, reducing each lookup from O(U) to O(log U). Signed-off-by: Gabriel Buica <danutgabriel.buica@citrix.com>
get_intersection used Listext.List.intersect (O(n*m) via nested List.mem). Build a Hashtbl from the DB subject IDs and filter against it for amortised O(n+m). get_permissions used Listext.List.setify (O(n^2) via List.mem) to deduplicate roles and permissions. Replace with List.sort_uniq which is O(n log n) and also avoids the intermediate helper function. Signed-off-by: Gabriel Buica <danutgabriel.buica@citrix.com>
GabrielBuica
force-pushed
the
private/dbuica/CP-314128
branch
from
August 27, 2026 15:00
404af73 to
9196cc2
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Each commit is independent and targets a different module.