Skip to content
MAR
Sign inRequest access
AI

Graph Neural Networks Outperform Language Models at Spotting Code Defects

Researchers develop a GNN-based system that detects problematic code patterns more efficiently and accurately than LLMs, using graph-level analysis of software structure.

MrBarisCMrBarisC@barisMarsel TeamCreator
CrawledarXiv cs.SE (Software Engineering)

A new deep learning approach using graph neural networks (GNNs) shows promise for identifying design flaws in source code—a problem traditionally tackled through manual inspection or computationally expensive AI models.

The method, described in a paper submitted to arXiv, addresses code smells—patterns that suggest underlying maintainability issues but don't necessarily cause immediate failures. Rather than relying on fixed rules or training on limited datasets, the researchers built a graph-based system that maps code structure at both class and method levels, then applies neural networks to classify problematic regions.

How it Works#

The team trained and tested three GNN variants—GCN, GraphSAGE, and GAT—on SACS, a large-scale dataset of open-source code compiled through semi-automated techniques. By representing code as interconnected graphs, the models can learn how functions and classes relate to each other, making it easier to spot when something breaks conventional design principles.

The approach focuses on three common code smells: Long Method (functions that do too much), Large Class (overstuffed classes), and Feature Envy (code that relies too heavily on another module's data).

Why This Matters#

Large language models have become popular for code analysis but carry a steep computational price tag, especially when scanning entire software systems. The GNN approach matches or exceeds LLM performance on refactoring tasks while using far fewer resources.

Experimental results showed the graph-based method outperformed traditional metric-driven detection, existing deep learning systems, and four lightweight LLM baselines across all tested scenarios. This suggests GNNs may offer a sweet spot between accuracy and efficiency for helping developers improve legacy code.

Essential cookies keep the site working and are always on. If you allow analytics, we also record sessions of visitors and of members aged 18 or over across the site, including messaging and profile pages: clicks, scrolls and page layout. Everything you write or upload, names, profile photos and images are masked in your browser before anything is sent, so the text you type never leaves it unmasked. Recordings are not used for advertising. Ad measurement is a separate choice. You can withdraw any time in settings.