Story Details

  • My failed attempt to shrink all NPM packages by 5%

    Posted: 2025-01-27 12:44:39

    A developer attempted to reduce the size of all npm packages by 5% by replacing all spaces with tabs in package.json files. This seemingly minor change exploited a quirk in how npm calculates package sizes, which only considers the size of tarballs and not the expanded code. The attempt failed because while the tarball size technically decreased, popular registries like npm, pnpm, and yarn unpack packages before installing them. Consequently, the space savings vanished after decompression, making the effort ultimately futile and highlighting the disconnect between reported package size and actual disk space usage. The experiment revealed that reported size improvements don't necessarily translate to real-world benefits and underscored the complexities of dependency management in the JavaScript ecosystem.

    Summary of Comments ( 47 )
    https://news.ycombinator.com/item?id=42840548

    HN commenters largely praised the author's effort and ingenuity despite the ultimate failure. Several pointed out the inherent difficulties in achieving universal optimization across the vast and diverse npm ecosystem, citing varying build processes, developer priorities, and the potential for unintended consequences. Some questioned the 5% target as arbitrary and possibly insignificant in practice. Others suggested alternative approaches, like focusing on specific package types or dependencies, improving tree-shaking capabilities, or addressing the underlying issue of JavaScript's verbosity. A few comments also delved into technical details, discussing specific compression algorithms and their limitations. The author's transparency and willingness to share his learnings were widely appreciated.