Back to articles
The Hidden Cost of Import Chains
NewsTools

The Hidden Cost of Import Chains

via Dev.toPeng Cao

You open a seemingly simple file in your codebase: // src/api/user-profile.ts (52 lines) import { validateUser } from ' ./validators ' ; import { formatResponse } from ' ./formatters ' ; import { logRequest } from ' ./logger ' ; export async function getUserProfile ( userId : string ) { validateUser ( userId ); const user = await fetchUser ( userId ); logRequest ( ' getUserProfile ' , userId ); return formatResponse ( user ); } Looks clean, right? Just 52 lines, three imports, straightforward logic. But when your AI assistant tries to understand this file, here's what actually gets loaded into its context window: src/api/user-profile.ts 52 lines 1,245 tokens └─ validators.ts 89 lines 2,134 tokens └─ validation-rules.ts 156 lines 3,721 tokens └─ error-types.ts 41 lines 982 tokens └─ formatters.ts 103 lines 2,456 tokens └─ format-utils.ts 78 lines 1,867 tokens └─ logger.ts 67 lines 1,603 tokens └─ log-transport.ts 124 lines 2,967 tokens └─ log-formatter.ts 91 lines 2,178 tokens Total: 80

Continue reading on Dev.to

Opens in a new tab

Read Full Article
3 views

Related Articles