From 496ce717c5343984e0f3da00d223604eff03893c Mon Sep 17 00:00:00 2001 From: Jonathan Schwender <55576758+jschwe@users.noreply.github.com> Date: Thu, 11 Jul 2024 15:24:52 +0200 Subject: Move legacy layout behind a feature flag (#32759) * Move legacy layout behind a feature flag For now the new feature flag would still be enabled by default, but disabling the `layout_2013` feature, gives the following binary size improvements for servoshell on Linux: - in debug mode from 1278MB -> 1201 MB - in release mode from 144MB -> 140MB - in production mode from 108MB -> 106MB Signed-off-by: Jonathan Schwender * Update components/servo/lib.rs Co-authored-by: Martin Robinson Signed-off-by: Jonathan Schwender <55576758+jschwe@users.noreply.github.com> --------- Signed-off-by: Jonathan Schwender Signed-off-by: Jonathan Schwender <55576758+jschwe@users.noreply.github.com> Co-authored-by: Martin Robinson --- components/servo/lib.rs | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) (limited to 'components/servo/lib.rs') diff --git a/components/servo/lib.rs b/components/servo/lib.rs index f130e99160b..1d1ef2bb988 100644 --- a/components/servo/lib.rs +++ b/components/servo/lib.rs @@ -67,6 +67,8 @@ use fonts::FontCacheThread; use gaol::sandbox::{ChildSandbox, ChildSandboxMethods}; pub use gleam::gl; use ipc_channel::ipc::{self, IpcSender}; +#[cfg(feature = "layout_2013")] +pub use layout_thread_2013; use log::{error, trace, warn, Log, Metadata, Record}; use media::{GLPlayerThreads, GlApi, NativeDisplay, WindowGLContext}; use net::resource_thread::new_resource_threads; @@ -98,10 +100,9 @@ use webrender_traits::{ pub use { background_hang_monitor, base, bluetooth, bluetooth_traits, canvas, canvas_traits, compositing, constellation, devtools, devtools_traits, embedder_traits, euclid, fonts, ipc_channel, - keyboard_types, layout_thread_2013, layout_thread_2020, media, net, net_traits, profile, - profile_traits, script, script_layout_interface, script_traits, servo_config as config, - servo_config, servo_geometry, servo_url as url, servo_url, style, style_traits, webgpu, - webrender_api, webrender_traits, + keyboard_types, layout_thread_2020, media, net, net_traits, profile, profile_traits, script, + script_layout_interface, script_traits, servo_config as config, servo_config, servo_geometry, + servo_url as url, servo_url, style, style_traits, webgpu, webrender_api, webrender_traits, }; #[cfg(feature = "webdriver")] @@ -968,6 +969,22 @@ fn create_compositor_channel( ) } +fn get_layout_factory(legacy_layout: bool) -> Arc { + cfg_if::cfg_if! { + if #[cfg(feature = "layout_2013")] { + if legacy_layout { + return Arc::new(layout_thread_2013::LayoutFactoryImpl()); + } + } else { + if legacy_layout { + warn!("Runtime option `legacy_layout` was enabled, but the `layout_2013` \ + feature was not enabled at compile time. Falling back to layout 2020! "); + } + } + } + Arc::new(layout_thread_2020::LayoutFactoryImpl()) +} + fn create_constellation( user_agent: Cow<'static, str>, config_dir: Option, @@ -1034,11 +1051,7 @@ fn create_constellation( wgpu_image_map, }; - let layout_factory: Arc = if opts::get().legacy_layout { - Arc::new(layout_thread_2013::LayoutFactoryImpl()) - } else { - Arc::new(layout_thread_2020::LayoutFactoryImpl()) - }; + let layout_factory: Arc = get_layout_factory(opts::get().legacy_layout); Constellation::< script::script_thread::ScriptThread, @@ -1213,11 +1226,8 @@ pub fn run_content_process(token: String) { set_logger(content.script_to_constellation_chan().clone()); let background_hang_monitor_register = content.register_with_background_hang_monitor(); - let layout_factory: Arc = if opts::get().legacy_layout { - Arc::new(layout_thread_2013::LayoutFactoryImpl()) - } else { - Arc::new(layout_thread_2020::LayoutFactoryImpl()) - }; + let layout_factory: Arc = + get_layout_factory(opts::get().legacy_layout); content.start_all::( true, -- cgit v1.2.3