diff --git a/Ladybird/HelperProcess.cpp b/Ladybird/HelperProcess.cpp index c1791981c64..cee43c3685d 100644 --- a/Ladybird/HelperProcess.cpp +++ b/Ladybird/HelperProcess.cpp @@ -104,6 +104,9 @@ ErrorOr> 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()); diff --git a/Ladybird/WebContent/main.cpp b/Ladybird/WebContent/main.cpp index 0d6c54900f7..340c343b1d5 100644 --- a/Ladybird/WebContent/main.cpp +++ b/Ladybird/WebContent/main.cpp @@ -105,6 +105,7 @@ ErrorOr 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 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 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) { diff --git a/Userland/Libraries/LibWebView/Application.cpp b/Userland/Libraries/LibWebView/Application.cpp index 04db1d0d6c3..d0ab3fa3fee 100644 --- a/Userland/Libraries/LibWebView/Application.cpp +++ b/Userland/Libraries/LibWebView/Application.cpp @@ -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); diff --git a/Userland/Libraries/LibWebView/Options.h b/Userland/Libraries/LibWebView/Options.h index 6c99d076f9a..a9972a1ae50 100644 --- a/Userland/Libraries/LibWebView/Options.h +++ b/Userland/Libraries/LibWebView/Options.h @@ -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 }; }; }