Repository: denoland/deno
File: cli/worker.rs (Rust)

Code before:
        .options
        .unsafely_ignore_certificate_errors
        .clone(),
      seed: shared.options.seed,
      create_web_worker_cb,
      format_js_error_fn: Some(Arc::new(format_js_error)),
      worker_type: args.worker_type,
      get_error_class_fn: Some(&errors::get_error_class_name),
      stdio: stdio.clone(),
      cache_storage_dir,
      strace_ops: shared.options.strace_ops.clone(),
      close_on_idle: args.close_on_idle,
      maybe_worker_metadata: args.maybe_worker_metadata,
    };

    WebWorker::bootstrap_from_options(services, options)
  })
}

#[allow(clippy::print_stdout)]
#[allow(clippy::print_stderr)]
#[cfg(test)]
mod tests {
  use super::*;
  use deno_core::resolve_path;
  use deno_core::FsModuleLoader;
  use deno_fs::RealFs;
  use deno_runtime::deno_permissions::Permissions;
  use deno_runtime::permissions::RuntimePermissionDescriptorParser;

  fn create_test_worker() -> MainWorker {
    let main_module =
      resolve_path("./hello.js", &std::env::current_dir().unwrap()).unwrap();
    let fs = Arc::new(RealFs);
    let permission_desc_parser =
      Arc::new(RuntimePermissionDescriptorParser::new(fs.clone()));
    let options = WorkerOptions {
      startup_snapshot: crate::js::deno_isolate_init(),
      ..Default::default()
    };

    MainWorker::bootstrap_from_options(
      main_module,
      WorkerServiceOptions {
        module_loader: Rc::new(FsModuleLoader),
        permissions: PermissionsContainer::new(
          permission_desc_parser,
          Permissions::none_without_prompt(),
        ),
        blob_store: Default::default(),
        broadcast_channel: Default::default(),

Review comment (performance):
![image](https://github.com/user-attachments/assets/b33f5ce1-4c52-4a4b-9110-9dc5a6d57f0d)

This seems very slow and negatively affects startup time.

Code after:
      create_params: create_isolate_create_params(),
      unsafely_ignore_certificate_errors: shared
        .options
        .unsafely_ignore_certificate_errors
        .clone(),
      seed: shared.options.seed,
      create_web_worker_cb,
      format_js_error_fn: Some(Arc::new(format_js_error)),
      worker_type: args.worker_type,
      get_error_class_fn: Some(&errors::get_error_class_name),
      stdio: stdio.clone(),
      cache_storage_dir,
      strace_ops: shared.options.strace_ops.clone(),
      close_on_idle: args.close_on_idle,
      maybe_worker_metadata: args.maybe_worker_metadata,
    };

    WebWorker::bootstrap_from_options(services, options)
  })
}

/// By default V8 uses 1.4Gb heap limit which is meant for browser tabs.
/// Instead probe for the total memory on the system and use it instead
/// as a default.
pub fn create_isolate_create_params() -> Option<v8::CreateParams> {
  let maybe_mem_info = deno_runtime::sys_info::mem_info();
  maybe_mem_info.map(|mem_info| {
    v8::CreateParams::default()
      .heap_limits_from_system_memory(mem_info.total, 0)
  })
}

#[allow(clippy::print_stdout)]
#[allow(clippy::print_stderr)]
#[cfg(test)]
mod tests {
  use super::*;
  use deno_core::resolve_path;
  use deno_core::FsModuleLoader;
  use deno_fs::RealFs;
  use deno_runtime::deno_permissions::Permissions;
  use deno_runtime::permissions::RuntimePermissionDescriptorParser;

  fn create_test_worker() -> MainWorker {
    let main_module =
      resolve_path("./hello.js", &std::env::current_dir().unwrap()).unwrap();
    let fs = Arc::new(RealFs);
    let permission_desc_parser =
      Arc::new(RuntimePermissionDescriptorParser::new(fs.clone()));
    let options = WorkerOptions {
      startup_snapshot: crate::js::deno_isolate_init(),