0

I'm using Playwright with .NET 7, for web scraping (not testing).

The major downfall compared to the Node tooling, is that it slows down my developer inner loop, due to the compilation before each run.

I'm not referring to it "in production", where the console app is published with all the extra bits stripped out, and it's quite fast. Rather, I'm referring to it during development, where one makes some tweak and reruns the app, then another tweak and another rerun... in Node that would be very fast, but in .NET there's the compile step every time.

For example, the following is a simple example console app from the docs.

Program.cs

using Microsoft.Playwright;

using var playwright = await Playwright.CreateAsync();
await using var browser = await playwright.Chromium.LaunchAsync();

var page = await browser.NewPageAsync();
await page.GotoAsync("https://playwright.dev/dotnet");

var title = await page.TitleAsync();
Console.WriteLine(title);

MyProject.csproj

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net7.0</TargetFramework>
    <RootNamespace>MyProject</RootNamespace>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.Playwright" Version="1.31.1" />
  </ItemGroup>
</Project>

The only tricks I'm using is to run it in RELEASE mode every time (rather than DEBUG), and skip nuget restore:

dotnet run --configuration Release --no-restore

Unfortunately, that doesn't provide any real benefit:

# DEBUG
$ time dotnet run
Fast and reliable end-to-end testing for modern web apps | Playwright .NET
dotnet run  6.26s user 0.71s system 144% cpu 4.814 total

# RELEASE
$ time dotnet run --configuration Release --no-restore
Fast and reliable end-to-end testing for modern web apps | Playwright .NET
dotnet run --configuration Release  4.32s user 0.75s system 91% cpu 5.518 total

When averaging over many samples, the figures are very similar. For a non-trivial scraping project, the figures are also similar.

What .csproj settings can I use to speed up the project configuration for this specific use case, and thus improve my developer "inner loop"?

lonix
  • 14,255
  • 23
  • 85
  • 176

0 Answers0