LibWebView: Add a browser flag to collect garbage after each allocation

This commit is contained in:
Timothy Flynn 2024-10-31 11:06:01 -04:00 committed by Alexander Kalenik
parent 171af8de33
commit be1d400369
Notes: github-actions[bot] 2024-10-31 23:37:36 +00:00
4 changed files with 17 additions and 0 deletions

View file

@ -104,6 +104,9 @@ ErrorOr<NonnullRefPtr<WebView::WebContentClient>> launch_web_content_process(
arguments.append("--force-cpu-painting"sv);
if (web_content_options.force_fontconfig == WebView::ForceFontconfig::Yes)
arguments.append("--force-fontconfig"sv);
if (web_content_options.collect_garbage_on_every_allocation == WebView::CollectGarbageOnEveryAllocation::Yes)
arguments.append("--collect-garbage-on-every-allocation"sv);
if (auto server = mach_server_name(); server.has_value()) {
arguments.append("--mach-server-name"sv);
arguments.append(server.value());

View file

@ -105,6 +105,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
bool enable_http_cache = false;
bool force_cpu_painting = false;
bool force_fontconfig = false;
bool collect_garbage_on_every_allocation = false;
Core::ArgsParser args_parser;
args_parser.add_option(command_line, "Chrome process command line", "command-line", 0, "command_line");
@ -122,6 +123,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
args_parser.add_option(enable_http_cache, "Enable HTTP cache", "enable-http-cache");
args_parser.add_option(force_cpu_painting, "Force CPU painting", "force-cpu-painting");
args_parser.add_option(force_fontconfig, "Force using fontconfig for font loading", "force-fontconfig");
args_parser.add_option(collect_garbage_on_every_allocation, "Collect garbage after every JS heap allocation", "collect-garbage-on-every-allocation");
args_parser.parse(arguments);
@ -171,6 +173,9 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
TRY(Web::Bindings::initialize_main_thread_vm(Web::HTML::EventLoop::Type::Window));
if (collect_garbage_on_every_allocation)
Web::Bindings::main_thread_vm().heap().set_should_collect_on_every_allocation(true);
TRY(initialize_resource_loader(Web::Bindings::main_thread_vm().heap(), request_server_socket));
if (log_all_js_exceptions) {

View file

@ -78,6 +78,7 @@ void Application::initialize(Main::Arguments const& arguments, URL::URL new_tab_
bool expose_internals_object = false;
bool force_cpu_painting = false;
bool force_fontconfig = false;
bool collect_garbage_on_every_allocation = false;
Core::ArgsParser args_parser;
args_parser.set_general_help("The Ladybird web browser :^)");
@ -98,6 +99,7 @@ void Application::initialize(Main::Arguments const& arguments, URL::URL new_tab_
args_parser.add_option(expose_internals_object, "Expose internals object", "expose-internals-object");
args_parser.add_option(force_cpu_painting, "Force CPU painting", "force-cpu-painting");
args_parser.add_option(force_fontconfig, "Force using fontconfig for font loading", "force-fontconfig");
args_parser.add_option(collect_garbage_on_every_allocation, "Collect garbage after every JS heap allocation", "collect-garbage-on-every-allocation", 'g');
args_parser.add_option(Core::ArgsParser::Option {
.argument_mode = Core::ArgsParser::OptionArgumentMode::Required,
.help_string = "Name of the User-Agent preset to use in place of the default User-Agent",
@ -153,6 +155,7 @@ void Application::initialize(Main::Arguments const& arguments, URL::URL new_tab_
.force_cpu_painting = force_cpu_painting ? ForceCPUPainting::Yes : ForceCPUPainting::No,
.force_fontconfig = force_fontconfig ? ForceFontconfig::Yes : ForceFontconfig::No,
.enable_autoplay = enable_autoplay ? EnableAutoplay::Yes : EnableAutoplay::No,
.collect_garbage_on_every_allocation = collect_garbage_on_every_allocation ? CollectGarbageOnEveryAllocation::Yes : CollectGarbageOnEveryAllocation::No,
};
create_platform_options(m_chrome_options, m_web_content_options);

View file

@ -95,6 +95,11 @@ enum class ForceFontconfig {
Yes,
};
enum class CollectGarbageOnEveryAllocation {
No,
Yes,
};
struct WebContentOptions {
String command_line;
String executable_path;
@ -108,6 +113,7 @@ struct WebContentOptions {
ForceCPUPainting force_cpu_painting { ForceCPUPainting::No };
ForceFontconfig force_fontconfig { ForceFontconfig::No };
EnableAutoplay enable_autoplay { EnableAutoplay::No };
CollectGarbageOnEveryAllocation collect_garbage_on_every_allocation { CollectGarbageOnEveryAllocation::No };
};
}