Clean architecture can make coding agents spend more tokens and time navigating layers, but that overhead depends on the task. An adapter boundary may repay the effort when a change replaces infrastructure. None of that, by itself, shows whether the finished application runs faster or slower: production runtime needs separate tracing and profiling.
First separate agent effort from application runtime
“Execution time” can mean two different things. For an AI coding agent, it is the time and model usage required to produce an accepted code change. For the application, it is the time a request takes while the software runs. Clean architecture may affect both, but through different mechanisms and with different evidence.
As an Amazon Associate I earn from qualifying purchases.
- Agent cost: measure input and output tokens, elapsed time to acceptance, tool calls, and repair rounds. More layers or files may require more context to understand a change.
- Application performance: measure request latency, resource use, and time spent in each stage under representative load. An agent needing more context does not establish that the deployed program has higher latency.
The available comparative examples concern agent work and repository structure. They do not establish a general production-runtime penalty or benefit for clean architecture.
What comparative agent-work evidence shows
A DEV Community article by Kristiyan Stoyanov reports an experiment on one Java electric-vehicle billing service. It compared flat and hexagonal implementations using a local Qwen model served through vLLM, fixed task checks, and one run per condition per task. The author reports lower total time for flat structure over most measured sequences, but a substantial advantage for hexagonal structure on a persistence-backend replacement.
#1 Best Overall
| Measured work | Flat structure | Hexagonal structure | Reported comparison |
|---|---|---|---|
| F1–F9 feature sequence | 165.93 minutes; 31.25 million input tokens | 228.57 minutes; 53.40 million input tokens | Hexagonal took 37.8% more acceptance time. |
| Six independent harder challenges | 161.55 minutes; 33.69 million input tokens | 174.24 minutes; 51.23 million input tokens | Hexagonal took 7.9% more acceptance time. |
| Cumulative S01–S15 sequence | 298.86 minutes; 83.04 million input tokens | 389.45 minutes; 126.86 million input tokens | Hexagonal took 30.3% more acceptance time. |
| Persistence-backend replacement | 71.25 minutes; 24.53 million input tokens | 38.92 minutes; 14.75 million input tokens | Hexagonal took 45.4% less time. |
| Cumulative S01–S16 sequence | 370.12 minutes | 428.37 minutes | Hexagonal took 15.7% more summed acceptance time. |
These are results from that author’s particular setup, not universal costs of adopting clean architecture. The initial implementations, architecture guidance, and internal test suites differed, so the comparison is between complete setups rather than architecture as an isolated variable. One run per condition also cannot establish how results vary across repeated attempts. The experiment does not identify a project-size threshold at which one approach becomes cheaper, or measure long-term maintenance cost. Read the experiment and its qualifications.
Why extra structure can cost agent context
Layers and boundaries can spread a small change across more files. An agent may need to locate an interface, implementation, wiring or configuration, and tests before it can make a safe edit. That navigation can increase prompt context and tool activity, especially when a task does not benefit from the boundary involved.
Rank #2
A GitLab Handbook design comparison for an Artifact Registry demo estimated that adding a format would require an agent to read about 9,500 input tokens in its Clean Architecture layout, compared with about 8,900 in its Go Native layout and about 11,700 in its DDD-plus-Hexagonal layout. These are estimates derived from character counts at approximately four characters per token, not observed model usage or billed tokens.
Free tools Windows power users keep installed
One-click scans. No signup required.
The same local comparison lists 36 Go files for the five-format Go Native demo and 65 for the Clean Architecture demo. For the simplest format, it lists four files and about 450 lines in Go Native versus 10 files and 628 lines in Clean Architecture. Those figures describe that demo, not fixed properties of the architecture styles. See GitLab’s design comparison.
When an adapter boundary can pay off
A boundary is most likely to help when the change is the kind it was designed to contain. In the reported billing-service experiment, replacing the persistence backend was faster in the hexagonal implementation and used fewer recorded input tokens than in the flat implementation. An adapter gave the change a defined place to happen rather than requiring the same kind of work to spread through the service.
That task-specific advantage did not outweigh the higher cumulative time and input-token totals across the experiment’s S01–S15 and S01–S16 sequences. The practical question is not whether an abstraction is “clean,” but whether representative changes repeatedly benefit from it enough to justify the extra wiring, files, tests, and navigation.
How to measure agent costs fairly
Compare the actual designs and work your project needs. A useful evaluation includes routine feature work and cross-cutting changes; include infrastructure replacement only if it is a realistic task for the product.
Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minutePC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11- Define representative tasks and acceptance checks. Keep task requirements, repository snapshot, validation, and agent setup consistent where feasible. Record differences in internal tests or architecture instructions, since they can change the amount of work.
- Log token use separately. Capture input and output tokens; record reasoning tokens if the platform exposes them. Do not infer billed usage from file counts or estimated context size.
- Record the whole path to an accepted change. Track elapsed time, agent work time, test or evaluation time, tool calls, and repair rounds. A quick first draft that needs repeated fixes may not be cheaper overall.
- Repeat tasks where feasible. The reported experiment used one run per task condition; repeated runs can show how sensitive your own result is to variation. Keep run order controlled where practical and report uncertainty rather than treating one result as a general law.
- Compare benefits with ongoing complexity. Count duplicated implementations, testing burden, wiring, and operational overhead alongside token and time measurements. Lines of code and token totals alone do not measure quality or lifetime cost.
How to measure application execution time
For production latency, instrument the request path rather than using agent token consumption as a proxy. Microsoft Learn advises: “Effective optimization begins with clear visibility into where time is spent.” Its AI application guidance recommends traces that help distinguish model time from delays in surrounding systems. Microsoft Learn’s AI app architecture guidance identifies measures such as time to first token (TTFT), total latency, queueing, retrieval and tool-call latency, token throughput, p95 and p99 latency, retries, and cost per request.
- Trace stages such as queueing, retrieval, tool calls, orchestration, model execution, and safety checks to find where latency accumulates.
- Profile hot code paths under representative traffic before restructuring code in pursuit of speed. Include CPU, memory, and I/O where relevant to the suspected bottleneck.
- Compare tail latency as well as averages: p95 and p99 can reveal slow requests hidden by a good mean.
- Account for observability overhead. Instrumentation helps identify bottlenecks, but it can itself add cost. Microsoft Azure’s code-cost guidance discusses that trade-off.
Include token and infrastructure costs in the same model
Token use is only one part of operating an AI application, and it should not be conflated with the runtime speed of the application’s own code. AWS recommends a living cost model that includes query patterns, average prompt and completion tokens, model token prices, and infrastructure costs. Depending on the application, infrastructure can include compute, vector databases, and guardrails. Update the model as query volume and the system change; AWS Prescriptive Guidance describes this approach.
For an architecture decision, compare the costs that matter to your workload: routine versus boundary-crossing tasks, accepted agent changes, production latency and resource use, and the maintenance or observability burden. Keep a layer when it solves a named project need; do not assume every additional boundary will produce future savings.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.
Recommended Free Tools




