Goal-Persistent Coding Agents as Scientific Performance Engineers: A Fixed-Radius Nearest-Neighbor Case Study
Organizations: Lawrence Berkeley National Laboratory, Berkeley, CA, USA
Abstract
Coding agents can pursue persistent objectives across many tool-use turns, but evidence that general-purpose agents can conduct rigorous scientific performance engineering remains limited. We present a repository-scale case study in which off-the-shelf Codex and Claude Code agents optimize fixed-radius nearest-neighbor (FRNN) search for particle tracking. Starting from a PyTorch-dependent CUDA implementation, the agents follow an executable goal that specifies exact-correctness tests, profiling requirements, and acceptance criteria without prescribing code transformations. In the primary sequential trajectory, they autonomously remove the PyTorch dependency and conduct hypothesis-driven optimization experiments. The resulting standalone C++/CUDA library exactly reproduces the targeted reference result. Its synchronous NumPy interface achieved 1.6-fold speedup over the original GPU-resident PyTorch interface, despite including host transfers. Similar speedups were observed across different GPU architectures and software stacks. An independent optimization rerun followed a different sequence of hypotheses and reached even better performance on the target workload. These results show that goal-persistent coding agents can act as experimental performance engineers, and that executable scientific contracts are needed both to guide and to validate their optimization.
Figures & tables
| Variant | Device (ms) | Outcome |
| Codex insertion top- , SM52 | 370.772 | Pre-selection baseline |
| Codex always-heap top- , SM52 | 346.110 | Rejected: sparse regression |
| Codex hybrid top- (32), SM52 | 358.924 | Superseded |
| Codex hybrid top- (24), SM52 | 357.715 | Retained design |
| Codex handoff, SM52 | 356.277 | Exact checkpoint |
| Claude baseline, SM75 | 360.341 | Session baseline |
| GPU | Stack | frnn_cuda host | Original FRNN | Speedup |
| RTX 2070 SUPER | 2.13.0 / 13.0 | 299.6 [299.1, 300.0] | 473.0 [472.3, 474.3] | 1.58 [1.58, 1.58] |
| A100-SXM4 (40 GB) | 2.13.0 / 13.0 | 166.6 [163.1, 171.1] | 244.7 [244.5, 244.9] | 1.47 [1.43, 1.50] |
| A100-SXM4 (80 GB) | 2.13.0 / 13.0 | 164.2 [162.8, 170.8] | 246.7 [246.5, 246.9] | 1.50 [1.45, 1.52] |
| A100-SXM4 (40 GB) | 2.8.0 / 12.9 | 177.2 [171.2, 189.1] | 244.7 [244.5, 244.9] | 1.38 [1.30, 1.43] |
| Variant | Device (ms) | Outcome |
| Native SM75 baseline | 307.861 | Reference |
| Warp-cooperative search | 537.598 | Rejected: slower |
| Append then post-sort | 292.526 | Core test passed |
| Grouped D12 distance loads | 252.996 | Core test passed |
| No distance early exit | 268.761 | Rejected: slower |
| Heap-free dispatch | 250.198 | Unsafe for dense inputs |
Coding Agents
Coding agents use language models, tools, and feedback to modify software and complete engineering tasks.
See all 141 papers