• Emily Andrews's avatar
    Modify mojo::internal::Validate* functions for 48KB disk space savings · bebb5c66
    Emily Andrews authored
    mojo::internal::ValidateStruct is not able to fold properly even though
    almost 90% of the disassembly of the defined template specializations is
    the same because the call to T::Validate is unique.
    
    This change slightly modifies the internals of mojo::internal::Validate*
    to call a new helper function which pulls out most of the similar
    functionality. While the helper function is also templated, because the
    compiled specializations are identical, the compiler is able to fold all
    the calls to the same function.
    
    This reduces the overall size of chrome.dll and chrome_child.dll by
    24 KB each for a total of 48 KB in disk space savings. If there are
    other dlls that compile in mojo, these will experience similar benefits.
    
    Other approaches considered included:
    - creating an interface which defined helper functions within
    T:Validate. While this did allow all the functions to fold for 400 KB
    savings, this also opened us to a security risk because the *_Data
    objects are sent via IPC and could be coming from anywhere.
    - Including the ScopedDepthTracker call in the helper. This resulted in
    bugs since the ScopedDepthTracker takes advantage of deconstructors to
    keep track of how far down we've recursed through Validate function.
    - Generalize the header validation code generated in T:Validate. This
    resulted in a size increase. The reason is that we know the number of
    loops at compile time, so the compiler is able to take advantage of loop
    unrolling.
    
    Bug: 988151
    Change-Id: I80e8d35005dc3ec1a8c09762bf14b0823af7c3bd
    Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1723023Reviewed-by: default avatarKen Rockot <rockot@google.com>
    Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
    Commit-Queue: Ken Rockot <rockot@google.com>
    Cr-Commit-Position: refs/heads/master@{#682339}
    bebb5c66
validation_util.h 8.57 KB