Nugget 24: Token Economy Management — Comments Are Not Free
Expanding, just a little, on Nugget 23, where the fundamental idea is "Token Economy Management" (TEM), I found something literally disturbing: The Cost of Good Habits → Comments.
Computer science professors have always told us that someone else will need to read our code and that, after we have departed, other software engineers and developers will look at what we did. Let them know with comments.
For the following test, the file IEnumerator from System.Collections was selected. TEM was analyzed. These are the findings:
==================================================
Traditional Comments vs. No Comments
==================================================
Commented Function Token Count: 295
Non-Commented Token Count: 65
Tokens Saved: 230
Context Window Reduction: 77.97%
==================================================
Remember, the LLM cannot filter comments. These comments must still be processed. Every one of those tokens enters the context window. Every one of those tokens must be embedded, attended to, and reasoned about.
Perhaps, if we were working only with Web APIs, we could offload documentation to metadata schemas such as OpenAPI (Swagger). This would alleviate the problem, allowing the inline XML comments associated with controllers and endpoints to be removed while letting the tooling generate the OpenAPI specification.
The message is not that comments are bad.
If the message you perceive after reading this note is that "we should not write comments," I apologize; that is not what I mean.
I am calling attention to the LLM processing burden because comments are no longer free.
For decades, comments were essentially a storage concern. In the age of LLMs, they are also a computational concern. Every token must be processed, and that processing carries a cost. TEM simply provides a way to measure that cost and make it visible.

Comments
Post a Comment