• Igor Mammedov's avatar
    kvm: memslots: replace heap sort with an insertion sort pass · 063584d4
    Igor Mammedov authored
    memslots is a sorted array.  When a slot is changed, heapsort (lib/sort.c)
    would take O(n log n) time to update it; an optimized insertion sort will
    only cost O(n) on an array with just one item out of order.
    
    Replace sort() with a custom sort that takes advantage of memslots usage
    pattern and the known position of the changed slot.
    
    performance change of 128 memslots insertions with gradually increasing
    size (the worst case):
    
          heap sort   custom sort
    max:  249747      2500 cycles
    
    with custom sort alg taking ~98% less then original
    update time.
    Signed-off-by: default avatarIgor Mammedov <imammedo@redhat.com>
    Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
    063584d4
kvm_main.c 75.8 KB