LLM Coding in Practice: Balancing Capability and Cost Under Heavy Token Consumption

    As AI-assisted programming becomes mainstream, choosing the right large language model and configuring an efficient workflow is key to developer productivity. This article presents a real-world case: refactoring the core algorithm of a graphics rendering library using a new-generation LLM series, consuming tens of millions of tokens at a cost of under $10. It analyzes the model's capability boundaries, cost structure, and engineering practices, offering practical guidance for teams evaluating LLM-driven development workflows.

    In today’s environment of increasingly popular AI-assisted programming, selecting the right large model and configuring workflows appropriately has become essential for improving development efficiency. The author recently completed a complex task involving a core algorithm refactor for a graphics rendering library, using a new-generation LLM series throughout. The total token consumption reached tens of millions, with costs under 100 RMB (roughly $10). This article walks through the full process, examining the model’s capability boundaries, cost structure, and key engineering practices, providing a reference for peers making similar decisions.

    1. Task Background and Challenges

    The task targeted a plotting library built on the Qt framework, whose core function is efficiently rendering large volumes of data points. The original implementation used a one-time downsampling strategy: a fixed-ratio sample was taken from all points at data load time. While this reduces rendering overhead, it has a fatal flaw: when users zoom in to inspect local details, the sampled points may miss critical trends, causing distorted charts or lost information.

    The improvement goal was clear: implement a viewport-adaptive dynamic downsampling algorithm that recomputes sampled points based on the current visible range whenever the plot window is zoomed or panned, ensuring that shape features of the original data are preserved at any zoom level. This involved not only algorithm design but also seamless integration with the existing rendering pipeline and stable performance.

    Previously, the project used a combination of a mainstream conversational model and a separate code model. With the release of the new model series, the author switched to it and conducted a systematic evaluation of its coding ability, reasoning efficiency, and cost.

    2. Model Configuration and Task Execution

    The entire task was completed through an agent orchestration framework that allows assigning different models to different roles. The author configured a high-reasoning version for core logic design, code review, and mathematical derivation, and a lightweight fast version for file retrieval, simple refactoring, and documentation generation. The division of labor was as follows:

    • Core architecture and algorithm design: high-reasoning version, with temperature lowered for stability.
    • Code implementation and debugging: high-reasoning version, combined with strict compile verification.
    • Dependency analysis and code search: lightweight fast version, to reduce waiting time.
    • Comment and commit message generation: lightweight fast version.

    After the task was submitted, the agent automatically decomposed the problem, planned the steps, and progressively completed the algorithm rewrite, unit tests, compile verification, and Git commits. The whole process took about two and a half hours, consuming 48 million tokens at a total cost of roughly 60 RMB (an average blended price of about 0.5 RMB per million tokens). Notably, this cost included multiple rounds of self-review, rollback, and retries, reflecting the model’s “thinking overhead” across iterative cycles.

    3. In-Depth Capability Evaluation: Coding Skill, Logical Rigor, and Engineering Fit

    3.1 Code Generation Quality: Near Top-Tier, But Use With Care

    Judging by the quality of the delivered code, the model’s programming ability is comparable to the strongest current open-source models, especially when handling complex data structures and algorithmic logic. The core of the downsampling algorithm is a spatial index + iterative nearest-neighbor strategy. The model independently designed a two-phase approach balancing speed and accuracy: first coarse sampling to build a KD-tree, then fine-grained lookup of nearby points within the viewport, plus an incremental update mechanism to avoid full rebuilds.

    However, the model occasionally produced code that “looks reasonable but performs poorly.” For example, the initial implementation failed to handle duplicate sampling of points at window edges, causing local density anomalies when zoomed in. This is a reminder to developers: code generated by LLMs must be validated by both automated testing and human review.

    3.2 Reasoning and Self-Correction: A Surprisingly Transparent “Chain of Thought”

    Unlike traditional models that output answers directly, this series explicitly generates intermediate reasoning steps in high-reasoning mode, effectively making the “thinking process” transparent. During debugging, the model located an array out-of-bounds error from compiler logs and proactively suggested adding a boundary-clipping function—an ability uncommon in earlier code models (such as pure static analyzers).

    The tradeoff is a dramatic increase in token consumption. In a single complex task, reasoning steps can consume 5-10x the tokens of the final code. In this task, roughly 70% of tokens were spent on “multi-round trial and error” and “self-explanation.” Therefore, for well-defined, simple changes, use the lightweight fast model; switch to high-reasoning mode only when multi-step reasoning is involved.

    3.3 Engineering Fit: Version Control and Collaboration Friendly

    The model generates commit messages matching the project’s style and creates Git commits according to team conventions, reducing developers’ mechanical work. It also supports context compression and incremental memory, allowing it to reference earlier modification history within a conversation and avoid repetitive questions. These features make sustained collaboration on large projects feasible.

    4. Cost Efficiency Deep Dive: Token Consumption Breakdown and Optimization

    4.1 Why Did One Task Consume 48 Million Tokens?

    Breaking down the token composition, the main consumption came from:

    • Tool calls and file reading: the agent scanned the project directory, read multiple source files, and located relevant classes and functions—about 15%.
    • Multi-round self-reflection: in high-reasoning mode, after each candidate solution the model evaluated and regenerated it, forming a “generate-verify-regenerate” loop—about 60%.
    • Compilation and test execution: each failed compile triggered the model to read error logs and fix issues—about 20%.
    • Final refactoring and documentation: only 5%.

    Clearly, the reasoning model’s “self-doubt” is the biggest token consumer. If task complexity is low, using high-reasoning mode wastes resources.

    4.2 Cost Optimization Strategy: Tiered Model Scheduling

    Based on this practice, a “fast-slow hybrid” scheduling strategy is recommended:

    • Low-cognition tasks such as file retrieval, simple regex replacements, and comment generation → lightweight fast model (cost is about 1/5 of high-reasoning, with 3x speed improvement).
    • Code review, algorithm design, and complex debugging → high-reasoning model, but with a “maximum rounds” limit to prevent unbounded recursion.
    • Introduce “human confirmation points”: pause at key decisions (such as changing project architecture) for developer confirmation before continuing, to prevent the model from going off track and wasting time.

    With these strategies, token consumption for typical refactoring tasks can be reduced by 40%-50% while maintaining the same output quality.

    5. Practical Insights and Outlook

    This experiment fully validated mainstream LLMs’ usability in real-world software development. Their capability has leaped from “code snippet generation” to “complete task delivery,” showing potential for self-correction and engineering collaboration. However, token cost and reasoning overhead remain the core bottlenecks to large-scale adoption. Developers should not blindly pursue “full automation” but instead play the roles of “architect” and “acceptance reviewer,” treating the model as a senior intern rather than a fully autonomous developer.

    For cloud providers, offering tiered token pricing plans and fine-grained reasoning control parameters (such as “thinking depth” and “maximum iterations”) will be key features for attracting professional developers. In the future, as model inference efficiency improves further, per-task token consumption could drop to a third of current levels, making “full-stack automated development” truly widespread.

    In short, LLM-assisted coding has moved from “showing off” to “getting practical.” With proper configuration and thorough validation, it can significantly improve the quality and speed of complex tasks while keeping costs within an acceptable range. Development teams should establish their own model adaptation layers and evaluation benchmarks early to stay competitive amid rapid technological iteration.