Ask
192
@pinned_versions ·

does trimming a 14mb deploy bundle actually move cold start or is it all runtime init

node 20, deploy artifact is about 14mb zipped and most of that is one large sdk plus a date library i use in three places. cold start sits around 1.2s and warm requests are 40ms. before i spend a day on bundling i want to know whether artifact size is the lever or whether the time is going somewhere else entirely. has anyone measured the difference on a real service?

9 answers Share
Report

Answering anonymously — a moderator will review it first.

  • @row_level_sam · 6mo ago

    i did exactly this experiment. bundling and tree shaking took the artifact from 14mb to just under 4mb and cold start went from about 1.2s to 1.05s, which was real but not what i had been promised. the actual win came afterwards from moving two sdk clients out of module scope and requiring them lazily inside the handlers that needed them, which took another 300ms off because most requests never construct them at all.

    211
    Share
    Reply

    Answering anonymously — a moderator will review it first.

    Report
  • @swatch_sonia · 6mo ago

    look at what your imports do rather than what they weigh. an orm that builds a schema at import, a validation library compiling schemas, a config module reading and parsing at load, an sdk client constructing a connection pool. a small module that does work at import costs more than a large one that only defines functions.

    178
    Share
    Reply

    Answering anonymously — a moderator will review it first.

    Report
  • @margin_notes_mo · 6mo ago · 2 replies

    measure the floor before you optimise anything. deploy a hello world in the same runtime and region, take its cold start, and everything above that number is yours to fix. on most platforms that floor is a few hundred milliseconds, so if you are at 1.2s you have several hundred milliseconds of your own code running at import time and that is where the day is best spent.

    236
    Share
    Reply

    Answering anonymously — a moderator will review it first.

    Report
    • @pinned_versions · 6mo ago

      the hello world floor is such an obvious control and i have never once done it.

      58
      Share
      Reply

      Answering anonymously — a moderator will review it first.

      Report
  • @kernel_ring_buf · 6mo ago

    lazy require the heavy things, keep module scope for pure definitions, and stop reading config at import. that is most of it.

    134
    Share
    Reply

    Answering anonymously — a moderator will review it first.

    Report
  • @rueben_alsop · 6mo ago · 3 replies

    pushing back a little on the size does not matter consensus. it depends on the platform, because some of them fetch and unpack your artifact before anything runs, and on the first invocation in a region that download is on the critical path. i saw a clear step change dropping under a size threshold on one provider and none at all on another, so the honest answer is that you have to measure on the platform you actually use.

    156
    Share
    Reply

    Answering anonymously — a moderator will review it first.

    Report
    • @row_level_sam · 6mo ago

      fair, and that matches my numbers being a modest improvement rather than none. it was worth doing, it just was not the whole story.

      74
      Share
      Reply

      Answering anonymously — a moderator will review it first.

      Report
    • @quiet_stacker · 6mo ago

      also depends whether you are on a zip style deploy or a container image, which are completely different cost curves for the same megabytes.

      88
      Share
      Reply

      Answering anonymously — a moderator will review it first.

      Report
  • @tabula_rasa_dev · 3h ago

    one thing worth checking first is whether the date library is even doing anything at import. i had a locale bundle being pulled in for a single format call and dropping to the built in formatter removed a chunk of both size and init in one commit.

    1
    Share
    Reply

    Answering anonymously — a moderator will review it first.

    Report