Automated Detection of Inter-Language Design Smells in Multi-Language Deep Learning Frameworks

Zengyang Li, Xiaoyong Zhang, Wenshuo Wang, Peng Liang, Ran Mo, Jie Tan, Hui Liu

Introduction

Modern Deep Learning Frameworks (DLFs) such as TensorFlow and PyTorch leverage a multi-language architecture to balance developer productivity with computational efficiency. Typically, Python serves as the high-level interface for users, while C/C++ handles performance-critical backend execution. However, this hybrid approach introduces a complex interface layer—a "no-man's-land"—where traditional single-language analysis tools fail to detect architectural weaknesses. These weaknesses, termed Inter-Language Design Smells (ILDS), represent poor programming practices at the language boundary that can lead to maintenance difficulties, memory leaks, and reduced system stability.

Methodology

To address the lack of visibility into these cross-language issues, this research introduces CPSMELL, an automated tool designed to detect ILDS in Python/C++ integrated systems. The methodology followed a structured three-phase pipeline.

Overview of the ILDS identification and extraction process.
  1. Smell Identification: The researchers mined diverse data sources, including technical documentation, GitHub repositories, and community discussions on Stack Overflow, to identify recurring pain points in multi-language integration. This resulted in the definition of seven distinct ILDS, ranging from code-level issues like "Lack of Static Declaration" to broader architectural flaws like "Excessive Inter-Language Communication."
  2. Tool Development (CPSMELL): The tool parses Python code into Abstract Syntax Trees (ASTs) and C/C++ code into XML representations. It specifically monitors three primary communication mechanisms: the Python/C API, pybind11, and ctypes.
  3. Empirical Study: CPSMELL was deployed to analyze 10 historical versions of five major DLFs to track the evolution and persistence of these smells over time.

The Integration Boundary

The complexity of the language boundary is best illustrated by the standard process for creating Python extensions. As shown in the figure below, the "glue" code requires multiple steps of definition and initialization.

Standard steps for defining Python extension modules in C/C++.

Errors or inefficiencies in these steps—such as failing to check return values during module initialization (Step 4)—can lead to "Silent Failures" or memory leaks that are notoriously difficult to debug.

Empirical Study and Datasets

The study evaluated five prominent open-source frameworks: TensorFlow (Google), PyTorch (Meta), Chainer (Preferred Networks), PaddlePaddle (Baidu), and MindSpore (Huawei). By analyzing the latest stable releases and historical versions spanning approximately three years, the authors were able to observe how these architectural "smells" emerge as systems scale.

Key Results and Discussion

The evaluation of CPSMELL demonstrated high efficacy and revealed concerning trends in framework development:

  • High Precision: Manual validation of 982 detected instances confirmed an overall tool accuracy of 98.17%.
  • Prevalence of Smells: Nearly 1,000 ILDS instances were identified in the latest versions of the studied frameworks. Two specific types—Long Lambda Functions (LLF) and Unused Native Entities (UNE)—accounted for 75% of all detections.
  • Evolutionary Trends: Contrary to expectations of architectural maturation, the number of inter-language smells generally increased as frameworks evolved. This suggests that the pressure to deliver new features often overrides the need for clean maintenance at the language interface.
  • Framework-Specific Patterns: Smells varied by framework architecture. For instance, MindSpore's class-based structure led to more "Large Inter-language Binding Classes," while PyTorch struggled with "Lack of Static Declaration."

Conclusion

The study highlights that while multi-language architectures are essential for modern DLFs, they introduce unique technical debts that are often overlooked. CPSMELL provides a robust starting point for managing these "smells." Future work will focus on expanding the tool's support to other language pairs (e.g., Python/Rust) and developing automated refactoring capabilities to help developers resolve these issues as they are detected.

Summary updated

BibTeX
@inproceedings{li2025automated,
  author = {Zengyang Li and Xiaoyong Zhang and Wenshuo Wang and Peng Liang and Ran Mo and Jie Tan and Hui Liu},
  title = {{Automated Detection of Inter-Language Design Smells in Multi-Language Deep Learning Frameworks}},
  booktitle = {Inf. Softw. Technol},
  year = {2025},
  url = {https://openreview.net/forum?id=MNFh97eE7D},
}
Figure