Implement a highly optimized Binary Search algorithm to find the insertion point of a target value in a sorted array.
Return the smallest index where the target can be inserted while preserving sorted order. If the target already exists, return its first occurrence; if it is larger than every element, return the array length. Implement the solution with logarithmic time and constant extra space.
def search_insert(nums, target):