The client library for Perl eases interactions with the Google Ads API, with minimal
configuration on your part. However, performance depends significantly on how
the library is used and integrated.

Most [general best practices](https://developers.google.com/google-ads/api/docs/best-practices/overview) are applicable to all languages.
This page covers performance guidance specific to Perl.

## Profile your application

Profile your application for both CPU and memory usage to identify performance
bottlenecks. [`Devel::NYTProf`](https://metacpan.org/pod/Devel::NYTProf) is a feature-rich Perl source code
profiler that you can use to analyze execution time.

## Perl version

Regularly upgrade to a newer Perl version to benefit from runtime performance
improvements. Download the latest release from the [CPAN Perl source
releases](https://www.cpan.org/src/), and check the minimum required version for the library in
the [README requirements](https://github.com/googleads/google-ads-perl/blob/HEAD/README.md#requirements).

## Logging

Extensive logging can incur significant execution time penalties and memory
consumption. Set the logging level to `WARN` for any code in production.

See the [Logging guide](https://developers.google.com/google-ads/api/docs/client-libs/perl/logging) for more details about configuring
summary and detail loggers.

## SearchStream versus Search

The Google Ads API provides two main methods to retrieve objects:
[`Search`](https://developers.google.com/google-ads/api/reference/rpc/v26/GoogleAdsService/Search) (which uses pagination) and
[`SearchStream`](https://developers.google.com/google-ads/api/reference/rpc/v26/GoogleAdsService/SearchStream) (which uses streaming). `SearchStream`
provides better performance than `Search`, though there are certain scenarios
where `Search` might be preferred.

For a detailed comparison of the two methods, see the [Streaming
guide](https://developers.google.com/google-ads/api/docs/reporting/streaming).

## Payload optimization and batching

To minimize network overhead and memory consumption:

- Request only the specific fields your application needs in your Google Ads Query Language (GAQL) queries.
- Group multiple mutate operations into a single `mutate` request rather than sending individual requests for each change.

## HTTP timeout

The Perl client library provides a setting for configuring HTTP timeouts at the
client level:

    my $api_client = Google::Ads::GoogleAds::Client->new({
      # Set HTTP timeout to 5 minutes (300 seconds).
      http_timeout => 300,
    });

The default value is `3600` seconds (1 hour), set based on the
`DEFAULT_HTTP_TIMEOUT` constant in [`Constants.pm`](https://github.com/googleads/google-ads-perl/blob/HEAD/lib/Google/Ads/GoogleAds/Constants.pm).
[Set a custom client timeout](https://developers.google.com/google-ads/api/samples/set-custom-client-timeouts) if you need to enforce a shorter
limit on the maximum time for an API call.

You can set the timeout to 2 hours or more, but the API may still time out
extremely long-running requests and return a `DEADLINE_EXCEEDED` error. If you
encounter this error, split the request into smaller chunks and execute them in
parallel. This avoids the situation where a long-running request fails and the
only way to recover is to trigger the request again from the start.