Token Sugar: Making Source Code Sweeter for LLMs through Token-Efficient Shorthand

Fuente: arXiv
Saved in:
Bibliographic Details
Main Authors: Sun, Zhensu, Yang, Chengran, Du, Xiaoning, Yang, Zhou, Li, Li, Lo, David
Format: Preprint
Published: 2025
Subjects:
Online Access:
Tags: Add Tag
No Tags, Be the first to tag this record!
_version_ 1866917133986824192
author Sun, Zhensu
Yang, Chengran
Du, Xiaoning
Yang, Zhou
Li, Li
Lo, David
author_facet Sun, Zhensu
Yang, Chengran
Du, Xiaoning
Yang, Zhou
Li, Li
Lo, David
contents Large language models (LLMs) have shown exceptional performance in code generation and understanding tasks, yet their high computational costs hinder broader adoption. One important factor is the inherent verbosity of programming languages, such as unnecessary formatting elements and lengthy boilerplate code. This leads to inflated token counts in both input and generated outputs, which increases inference costs and slows down the generation process. Prior work improves this through simplifying programming language grammar, reducing token usage across both code understanding and generation tasks. However, it is confined to syntactic transformations, leaving significant opportunities for token reduction unrealized at the semantic level. In this work, we propose Token Sugar, a concept that replaces frequent and verbose code patterns with reversible, token-efficient shorthand in the source code. To realize this concept in practice, we designed a systematic solution that mines high-frequency, token-heavy patterns from a code corpus, maps each to a unique shorthand, and integrates them into LLM pretraining via code transformation. With this solution, we obtain 799 (code pattern, shorthand) pairs, which can reduce up to 15.1% token count in the source code and is complementary to existing syntax-focused methods. We further trained three widely used LLMs on Token Sugar-augmented data. Experimental results show that these models not only achieve significant token savings (up to 11.2% reduction) during generation but also maintain near-identical Pass@1 scores compared to baselines trained on unprocessed code.
format Preprint
id arxiv_https___arxiv_org_abs_2512_08266
institution arXiv
publishDate 2025
record_format arxiv
spellingShingle Token Sugar: Making Source Code Sweeter for LLMs through Token-Efficient Shorthand
Sun, Zhensu
Yang, Chengran
Du, Xiaoning
Yang, Zhou
Li, Li
Lo, David
Software Engineering
Large language models (LLMs) have shown exceptional performance in code generation and understanding tasks, yet their high computational costs hinder broader adoption. One important factor is the inherent verbosity of programming languages, such as unnecessary formatting elements and lengthy boilerplate code. This leads to inflated token counts in both input and generated outputs, which increases inference costs and slows down the generation process. Prior work improves this through simplifying programming language grammar, reducing token usage across both code understanding and generation tasks. However, it is confined to syntactic transformations, leaving significant opportunities for token reduction unrealized at the semantic level. In this work, we propose Token Sugar, a concept that replaces frequent and verbose code patterns with reversible, token-efficient shorthand in the source code. To realize this concept in practice, we designed a systematic solution that mines high-frequency, token-heavy patterns from a code corpus, maps each to a unique shorthand, and integrates them into LLM pretraining via code transformation. With this solution, we obtain 799 (code pattern, shorthand) pairs, which can reduce up to 15.1% token count in the source code and is complementary to existing syntax-focused methods. We further trained three widely used LLMs on Token Sugar-augmented data. Experimental results show that these models not only achieve significant token savings (up to 11.2% reduction) during generation but also maintain near-identical Pass@1 scores compared to baselines trained on unprocessed code.
title Token Sugar: Making Source Code Sweeter for LLMs through Token-Efficient Shorthand
topic Software Engineering
url https://arxiv.org/abs/2512.08266