The Google Ads .NET client library simplifies your app's interactions with the Google Ads API, with minimal configuration on your part. However, the overall performance highly depends on how the library is used and integrated with your app.
This guide covers performance optimizations that are specific to .NET applications, and complements the best practices that are generally applicable to the Google Ads API.
Compile for release build
Make sure you compile your app using Release configuration when deploying to the server. When using the Debug configuration, your app compiles with full symbolic debug information and no optimization.
Profile your app
Profile your app both for CPU and memory usage to identify performance bottlenecks. Visual Studio provides Diagnostic tools to help profile your app. There are also other commercial profiling tools that are available.
Use async methods
Asynchronous programming using the async-await paradigm helps avoid performance bottlenecks and enhance the overall responsiveness of your app. The Google Ads .NET library generates async methods for all services and RPC methods.
Turn off logging when possible
The Google Ads .NET library turns off logging by default and uses a lazy logging approach which gives your app better performance. If you turn on logging, make sure you turn it off in the production environment. If you need to monitor for specific failing requests in production, you can do one or more of the following steps without adversely affecting your app's performance:
- Turn on just the summary logs.
- Set the full logs to
- Save the request ID for specific requests of interest that you can share with the support channels.
See the logging guide to learn more.
Decide whether to use the SearchStream or Search method
The Google Ads API provides two main ways to retrieve objects: the
(which uses pagination) and
SearchStream (which uses streaming).
SearchStream provides better performance over
Search, but there are
Search is preferred.
See the streaming reports guide to learn more about the two methods.
Use ReadyToRun option
.NET Core 3.1 adds support for precompiling your binaries to a specific platform
and architecture by specifying a
PublishReadyToRun setting to
then publishing the binary by specifying a valid
publishing. See the guide on the
feature to learn
TieredCompilation allows .NET to identify hotspots and improve its performance.
Tiered compilation works better with the
ReadyToRun option since it can use
the pre-generated image when available. See the guide on
to learn more.
Fine-tune your garbage collection (GC)
.NET provides two general profiles for garbage collection (GC): a workstation profile and a server profile. These two profiles have differing performance tradeoffs. Apps using the Google Ads .NET library tend to perform better when running in a server profile. You can benefit from fine tuning the following GC settings.
Server garbage collection: Server garbage collection allows .NET runtime to give better performance to a Google Ads API app by operating on multiple threads. See this guide for more details. You can turn on server garbage collection by adding the following lines to your app's
<PropertyGroup> <ServerGarbageCollection>true</ServerGarbageCollection> </PropertyGroup>
Concurrent garbage collection: You can turn on concurrent garbage collection to give .NET GC a dedicated thread for garbage collection in generation 2. This setting can be useful when processing reports with large sizes. You can turn on concurrent garbage collection by adding the following lines to your app's
<PropertyGroup> <ConcurrentGarbageCollection>true</ConcurrentGarbageCollection> </PropertyGroup>
Retain VM garbage collection: The
RetainVMGarbageCollectionsetting configures whether segments of virtual memory that should be deleted are put on a standby list for future use, or are released back to the operating system (OS). You can turn on virtual memory retention by adding the following lines to your app.
<PropertyGroup> <RetainVMGarbageCollection>true</RetainVMGarbageCollection> </PropertyGroup>```
It is also possible to fine tune your GC by settling for a setup that is between
a workstation and a server. All the relevant
are specified in your .NET Core app's
runtimeconfig.json file, an environment
variable, or your .NET SDK app’s