---
schema_version: "1"
id: bd55c44d06f9a49d069752387ac4a35f49603b9bdb5e590f1e6e1804ed604b85
title: "ApexGuru Antipattern: Expensive Debug Statements"
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/xcloud/264-0-0/apexguru_antipattern_expensive_debug_statements.md
canonical_url: https://help.salesforce.com/s/articleView?id=xcloud.apexguru_antipattern_expensive_debug_statements.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: b6313bdaa6dee313eb8e602b935c33adfc3076c99c8ae42e2e1c28924c26cf10
description: Overusing System.debug() slows down execution, especially in production environments. Writing large amounts of data to logs increases the execution time and affects performance. Plus, the logs fill, making it harder to identify important issues.
products:
  - Cross Cloud
release: "264"
---
# ApexGuru Antipattern: Expensive Debug Statements

Overusing System.debug() slows down execution, especially in production environments. Writing large amounts of data to logs increases the execution time and affects performance. Plus, the logs fill, making it harder to identify important issues.

## Scope

Detection and recommendation

## Detection Example

```java
apex
  System.debug('Heap Size: ' + Limits.getHeapSize());
```

## Recommendation

To make sure that expensive operations aren’t evaluated unless necessary, perform a conditional check before invoking the call. Minimize debug statements in production code. Use conditional checks before invoking expensive calls, especially if the debug statement involves expensive computations such as `Limits.getHeapSize`.

```java
apex
// Commenting out the debug log in production environments 
// System.debug('Heap Size: ' + Limits.getHeapSize());
```