Closed
Description
The memory increase can be observed when enabling any check that uses ASTContext::getParents
in clang-tidy
. By plotting the memory consumption when analyzing a sample file, I got the following chart which shows around 10x increase in memory consumption in clang-tidy-19 compared to clang-tidy-18 when the number of elements in the array is large enough:
When the number of elements is close to 10M, memory consumption goes from about 3GB before clang-tidy-19 to about 30GB on clang-19.
Here is a script that generates the above plot:
import matplotlib.pyplot as plt
import subprocess
def generate_cpp_file(file_name, num_elements):
elements = [100] * num_elements
elements_str = ', '.join(map(hex, elements))
with open(file_name, 'w') as f:
f.write(f"""
const char large_array[] = {{
{elements_str}
}};
""")
def measure_memory_consumption_with(clang_tidy_bin, num_elements):
file_name = f'file_{num_elements}.cpp'
generate_cpp_file(file_name, num_elements)
process = subprocess.run(['/usr/bin/time', '-f', '%M', clang_tidy_bin, '-checks=readability-magic-numbers', file_name, '--', '-std=c++17'], check=True, capture_output=True)
memory_kb = int(process.stderr)
return memory_kb // 1024
def plot_memory_consumption():
num_elements = [10 ** 1, 10 ** 2, 10 ** 3, 10 ** 4, 10 ** 5, 10 ** 6, 3 * 10 ** 6, 5 * 10 ** 6, 8 * 10 ** 6]
memory_consumption_17 = [measure_memory_consumption_with('clang-tidy-17', n) for n in num_elements]
memory_consumption_18 = [measure_memory_consumption_with('clang-tidy-18', n) for n in num_elements]
memory_consumption_19 = [measure_memory_consumption_with('clang-tidy-19', n) for n in num_elements]
plt.plot(num_elements, memory_consumption_17, label='clang-tidy-17')
plt.plot(num_elements, memory_consumption_18, label='clang-tidy-18')
plt.plot(num_elements, memory_consumption_19, label='clang-tidy-19')
plt.xlabel('Number of elements')
plt.ylabel('Memory consumption (MB)')
plt.legend()
plt.show()
if __name__ == '__main__':
plot_memory_consumption()
I have installed clang-tidy
binaries in this test from apt.llvm.org on an Ubuntu machine.
Metadata
Metadata
Assignees
Type
Projects
Status
Done