DescriptionBlink class layout optimization to reduce memory usage
This change optimizes class layout on 64-bit in 4 blink classes, all
related to images. Considering the 16 bit allocation granularity
this saves 16 bytes per instance of each class. It looks like a
typical web page might have up to a few hundred instances of each
class so the total memory saving ~ 16-32 KB per Renderer process,
potentially more for image heavy pages.
UPDATE: crrev.com/2746343002 added a new field to ImageResourceContent
which further increased it size by 8 bytes. I've moved the fields
around again to still make it squeeze into 80 bytes.
Layout details:
Before:
class blink::Image [sizeof = 40]
: public WTF::ThreadSafeRefCounted<blink::Image> {
vfptr +0x00 [sizeof=8]
base +0x08 [sizeof=4] WTF::ThreadSafeRefCounted<blink::Image>
<padding> (4 bytes)
data +0x10 [sizeof=8] WTF::RefPtr<blink::SharedBuffer> encoded_image_data_
data +0x18 [sizeof=8] blink::UntracedMember<blink::ImageObserver> image_observer_
data +0x20 [sizeof=1] bool image_observer_disabled_
<padding> (7 bytes)
}
After:
class blink::Image [sizeof = 32]
: public WTF::ThreadSafeRefCounted<blink::Image> {
vfptr +0x00 [sizeof=8]
base +0x08 [sizeof=4] WTF::ThreadSafeRefCounted<blink::Image>
data +0x0c [sizeof=1] bool image_observer_disabled_
<padding> (3 bytes)
data +0x10 [sizeof=8] WTF::RefPtr<blink::SharedBuffer> encoded_image_data_
data +0x18 [sizeof=8] blink::UntracedMember<blink::ImageObserver> image_observer_
}
Before:
class blink::BitmapImage [sizeof = 280]
: public blink::Image {
base +0x00 [sizeof=33] blink::Image
<padding> (7 bytes)
data +0x28 [sizeof=112] blink::ImageSource source_
data +0x98 [sizeof=8] blink::IntSize size_
data +0xa0 [sizeof=8] blink::IntSize size_respecting_orientation_
data +0xa8 [sizeof=8] unsigned __int64 current_frame_
data +0xb0 [sizeof=40] WTF::Vector<blink::FrameData,1,WTF::PartitionAllocator> frames_
data +0xd8 [sizeof=8] sk_sp<SkImage> cached_frame_
data +0xe0 [sizeof=8] unsigned __int64 cached_frame_index_
data +0xe8 [sizeof=8] std::unique_ptr<...> frame_timer_
data +0xf0 [sizeof=4] int repetition_count_
data +0xf4 [sizeof=4] blink::BitmapImage::RepetitionCountStatus repetition_count_status_
data +0xf8 [sizeof=4] int repetitions_complete_
<padding> (4 bytes)
data +0x100 [sizeof=8] double desired_frame_start_time_
data +0x108 [sizeof=8] unsigned __int64 frame_count_
data +0x110 [sizeof=4] blink::ImageAnimationPolicy animation_policy_
data +0x114 [sizeof=1] bool animation_finished_ : 1
data +0x114 [sizeof=1] bool all_data_received_ : 1
data +0x114 [sizeof=1] bool have_size_ : 1
data +0x114 [sizeof=1] bool size_available_ : 1
data +0x114 [sizeof=1] bool have_frame_count_ : 1
<padding> (3 bytes)
}
After:
class blink::BitmapImage [sizeof = 264]
: public blink::Image {
base +0x00 [sizeof=32] blink::Image
data +0x20 [sizeof=112] blink::ImageSource source_
data +0x90 [sizeof=8] blink::IntSize size_
data +0x98 [sizeof=8] blink::IntSize size_respecting_orientation_
data +0xa0 [sizeof=8] unsigned __int64 current_frame_
data +0xa8 [sizeof=40] WTF::Vector<blink::FrameData,1,WTF::PartitionAllocator> frames_
data +0xd0 [sizeof=8] sk_sp<SkImage> cached_frame_
data +0xd8 [sizeof=8] unsigned __int64 cached_frame_index_
data +0xe0 [sizeof=8] std::unique_ptr<...> frame_timer_
data +0xe8 [sizeof=4] blink::ImageAnimationPolicy animation_policy_
data +0xec [sizeof=1] bool animation_finished_ : 1
data +0xec [sizeof=1] bool all_data_received_ : 1
data +0xec [sizeof=1] bool have_size_ : 1
data +0xec [sizeof=1] bool size_available_ : 1
data +0xec [sizeof=1] bool have_frame_count_ : 1
data +0xed [sizeof=1] blink::BitmapImage::RepetitionCountStatus repetition_count_status_
<padding> (2 bytes)
data +0xf0 [sizeof=4] int repetition_count_
data +0xf4 [sizeof=4] int repetitions_complete_
data +0xf8 [sizeof=8] double desired_frame_start_time_
data +0x100 [sizeof=8] unsigned __int64 frame_count_
}
Before:
class blink::ImageResourceContent [sizeof = 96]
: public blink::GarbageCollectedFinalized<blink::ImageResourceContent>
, public blink::ImageObserver {
base +0x00 [sizeof=8] blink::ImageObserver
base +0x08 [sizeof=1] blink::GarbageCollectedFinalized<blink::ImageResourceContent>
<padding> (7 bytes)
data +0x10 [sizeof=8] blink::Member<blink::ImageResourceInfo> info_
data +0x18 [sizeof=4] blink::ResourceStatus content_status_
<padding> (4 bytes)
data +0x20 [sizeof=8] WTF::RefPtr<blink::Image> image_
data +0x28 [sizeof=24] WTF::HashCountedSet<...> observers_
data +0x40 [sizeof=24] WTF::HashCountedSet<...> finished_observers_
data +0x58 [sizeof=4] blink::Image::SizeAvailability size_available_
data +0x5C [sizeof=1] bool is_refetchable_data_from_disk_cache_
data +0x5D [sizeof=1] bool is_add_remove_observer_prohibited_
<padding> (2 bytes)
}
After:
class blink::ImageResourceContent [sizeof = 80]
: public blink::GarbageCollectedFinalized<blink::ImageResourceContent>
, public blink::ImageObserver {
base +0x00 [sizeof=8] blink::ImageObserver
base +0x08 [sizeof=1] blink::GarbageCollectedFinalized<blink::ImageResourceContent>
data +0x09 [sizeof=1] blink::ResourceStatus content_status_
data +0x0a [sizeof=1] bool is_refetchable_data_from_disk_cache_
data +0x0b [sizeof=1] bool is_add_remove_observer_prohibited_
data +0x0c [sizeof=4] blink::Image::SizeAvailability size_available_
data +0x10 [sizeof=8] blink::Member<blink::ImageResourceInfo> info_
data +0x18 [sizeof=8] WTF::RefPtr<blink::Image> image_
data +0x20 [sizeof=24] WTF::HashCountedSet<...> observers_
data +0x38 [sizeof=24] WTF::HashCountedSet<...> finished_observers_
}
Before:
class blink::DeferredImageDecoder [sizeof = 96] {
data +0x00 [sizeof=8] std::unique_ptr<...> rw_buffer_
data +0x08 [sizeof=1] bool all_data_received_
<padding> (7 bytes)
data +0x10 [sizeof=8] std::unique_ptr<...> actual_decoder_
data +0x18 [sizeof=8] WTF::String filename_extension_
data +0x20 [sizeof=8] blink::IntSize size_
data +0x28 [sizeof=4] int repetition_count_
data +0x2c [sizeof=1] bool has_embedded_color_space_
<padding> (3 bytes)
data +0x30 [sizeof=8] sk_sp<SkColorSpace> color_space_for_sk_images_
data +0x38 [sizeof=1] bool can_yuv_decode_
data +0x39 [sizeof=1] bool has_hot_spot_
<padding> (2 bytes)
data +0x3c [sizeof=8] blink::IntPoint hot_spot_
<padding> (4 bytes)
data +0x48 [sizeof=16] WTF::Vector<...> frame_data_
data +0x58 [sizeof=8] WTF::RefPtr<...> frame_generator_
}
After:
class blink::DeferredImageDecoder [sizeof = 80] {
data +0x00 [sizeof=8] std::unique_ptr<...> rw_buffer_
data +0x08 [sizeof=8] std::unique_ptr<...> actual_decoder_
data +0x10 [sizeof=8] WTF::String filename_extension_
data +0x18 [sizeof=8] blink::IntSize size_
data +0x20 [sizeof=4] int repetition_count_
data +0x24 [sizeof=1] bool has_embedded_color_space_
data +0x25 [sizeof=1] bool all_data_received_
data +0x26 [sizeof=1] bool can_yuv_decode_
data +0x27 [sizeof=1] bool has_hot_spot_
data +0x28 [sizeof=8] sk_sp<SkColorSpace> color_space_for_sk_images_
data +0x30 [sizeof=8] blink::IntPoint hot_spot_
data +0x38 [sizeof=16] WTF::Vector<...> frame_data_
data +0x48 [sizeof=8] WTF::RefPtr<...> frame_generator_
}
BUG=710933
Review-Url: https://codereview.chromium.org/2859313003
Cr-Commit-Position: refs/heads/master@{#470373}
Committed: https://chromium.googlesource.com/chromium/src/+/4f54bee9b89dd593c338dbc684f806bb73b48256
Patch Set 1 #Patch Set 2 : Fix build error #Patch Set 3 : Resolved merge conflict and changed blink::ResourceStatus enum to be based on uint8_t #Messages
Total messages: 34 (24 generated)
|