Why Fast Code Often Loses: The Hidden Cost of Acting Before the Search Is Ready
Hatched by Kai Nguyen
May 29, 2026
9 min read
3 views
72%
The counterintuitive mistake behind many fast systems
What if the thing that makes a system feel fast is also what makes it fragile, premature, and occasionally wrong? In software, we often praise anything that happens sooner. Load earlier. Respond earlier. Execute earlier. But speed without sequencing is not intelligence, it is merely motion.
That tension appears in a surprisingly broad place: the choice between async and defer in JavaScript, and the way we model problems as state spaces in search. Both are really about the same question: when should action begin, and what must be known before action becomes safe?
A browser parsing HTML is a bit like a mind traversing a search space. It is gathering context, building structure, and keeping track of what is already known. Drop in a script too early, and the process stops. Let the script arrive asynchronously and it may run the moment it is ready, whether or not the rest of the structure exists. Defer it, and the script waits until the structure is complete, preserving order and meaning.
That small distinction reveals a larger principle: the best systems do not merely optimize for the earliest possible action. They optimize for the earliest valid action.
The browser is not just a machine, it is a search process
It is easy to think of page loading as a mechanical sequence: request, download, parse, execute. But the browser is doing something more subtle. As it parses HTML, it is constructing a live model of the page, a partially explored state space in which each tag changes what can happen next.
A state space is just a way of thinking about all possible configurations a problem can take. In a maze, each position is a state. In a chess game, each board arrangement is a state. In page loading, each partially parsed document is a state. The browser is not simply moving forward in time. It is continuously asking: what is now possible, given what has already been discovered?
That is why blocking scripts are so costly. They interrupt the exploration. Parsing stops until the script is fetched and executed, and the browser must pause its search before it has enough context to continue efficiently. By contrast, an async script says: fetch in parallel, then execute as soon as ready. This is fast in one sense, but it also introduces uncertainty in the order of execution. A defer script also fetches in parallel, but execution is postponed until parsing is complete, which preserves the browser’s ability to finish building the page before taking action.
This is the deeper lesson: parallelism is not the same as readiness.
Speed is not the absence of waiting. Speed is the removal of unnecessary waiting.
That distinction matters because many systems confuse “available” with “safe.” A script can be downloaded and still be in the wrong position to execute. A move in a search space can be legal and still be strategically terrible. A candidate state can be reachable and still be premature.
Async and defer as two philosophies of action
The contrast between async and defer is not just technical, it is philosophical.
Async is opportunistic. It says: the moment this piece of work is ready, let it run. That is excellent when the task is independent, self-contained, and not sensitive to surrounding order. Analytics tags, standalone widgets, and isolated utilities often fit this model. The virtue of async is responsiveness.
Defer is contextual. It says: wait until the structure is in place, then execute in order. That is valuable when a script depends on the DOM, on earlier scripts, or on a sequence of operations that must remain stable. The virtue of defer is coherence.
This tension mirrors decision making in complex problems. Sometimes the correct move is to act as soon as you have enough local evidence. Sometimes the correct move is to delay action until you have the broader structure, because a local optimum will mislead you. In a search process, that is the difference between greedily expanding the most obvious state and waiting to evaluate states in a way that respects the whole problem.
A useful mental model is to think of every system as having two clocks:
- The arrival clock, which measures when a resource becomes available.
- The dependency clock, which measures when action becomes valid.
Great engineering, great reasoning, and great planning all try to align those clocks. Problems begin when we treat the arrival of information as proof that action is now correct.
Why premature execution feels efficient, then becomes expensive
Premature execution is seductive because it produces visible progress. A script runs sooner. A page seems more interactive. A decision gets made. A branch in a search tree gets explored. The system appears active, and activity is easy to mistake for value.
But in many environments, acting too soon creates hidden costs that compound later. A script that fires before the DOM exists may fail silently or require brittle workarounds. A plan formed before the relevant constraints are known will need revision. A search algorithm that commits too early can waste enormous effort exploring a state that looked promising before the structure of the problem was clear.
This is one reason experienced engineers are often suspicious of “fast” solutions that ignore ordering. The real cost is not the execution itself. The cost is the repair work required when execution outruns understanding.
Consider a web page that loads a navigation menu, a payment widget, and a reporting script. If the reporting script is async, it might execute before the menu or widget has been initialized. If it assumes the DOM is ready, it may fail. If it is defer, it will wait until the HTML is parsed and then run in order, reducing coordination bugs. The page may not have started every individual task as early as possible, but it has started them in a way that minimizes wasted motion.
The same pattern appears in search. A search space can be traversed very quickly if you ignore constraints, but then you are not solving the right problem. The art lies in finding the earliest point at which a choice is both available and meaningful.
That is the real optimization target. Not earliest possible action. Earliest defensible action.
The best systems respect structure before urgency
There is a tempting assumption in modern design: if something is important, it should be made available immediately. But immediacy is not always an advantage. Sometimes the system needs structure before urgency.
Think about reading a book while someone interrupts you with random pages from the middle. The information may be correct, but it is not yet usable because the conceptual scaffold is missing. A defer script behaves more like handing you the chapters in order after the table of contents is in place. An async script behaves more like delivering whatever chapter finished printing first, regardless of where it belongs.
Now map that to state space search. The reason search works is not because it examines everything. It works because it uses structure to prune chaos. A problem becomes tractable when you can say: these states matter more, these transitions are legal, these partial paths preserve meaning, these do not. Without structure, search degenerates into wandering.
This gives us a more general framework:
- Async is for independent work where order does not define meaning.
- Defer is for dependent work where order creates meaning.
- State space search is the discipline of exploring possibilities without losing the structure that makes those possibilities intelligible.
Together they suggest a principle for building robust systems: parallelize acquisition, sequence interpretation.
In other words, gather information as quickly as possible, but delay irreversible action until the relevant state has stabilized.
A practical framework: ask three questions before you act
When facing a complex system, whether in code, planning, or analysis, use this simple test.
1. Is this work independent?
If a task can run without knowing the full state of the system, it can often be handled like async. An example is loading an image, fetching telemetry, or calculating a report that does not affect layout or initialization.
2. Does order matter?
If one operation depends on another, defer is usually safer. Order matters whenever a later step needs a completed structure, a stable environment, or a guaranteed predecessor. In search, this is the difference between a valid transition and a misleading shortcut.
3. What is the cost of being wrong early?
This is the most important question. If a premature action is cheap to correct, early execution may be worth it. If it creates cascading errors, hidden race conditions, or distorted search paths, delay is not a weakness. It is discipline.
The goal is not to start everything immediately. The goal is to start each thing at the moment it becomes meaningful.
This framework applies surprisingly well beyond software. In hiring, do you make a decision after one impressive signal, or after enough evidence to interpret the signal? In strategy, do you launch before the system is ready, or do you wait until dependencies are resolved? In personal knowledge work, do you rush to conclusions, or do you build the state space first, then search it?
The common mistake is mistaking speed for clarity. But clarity often comes from sequencing.
Key Takeaways
- Fast is not always better than ordered. The earliest possible action is often less valuable than the earliest valid action.
- Async and defer model two kinds of work. Use async for independent tasks, defer for tasks that depend on structure or sequence.
- Think in state spaces. A problem is easier to solve when you can represent the possible states and transitions clearly.
- Avoid premature commitment. Acting before the system is ready often creates hidden repair costs later.
- Optimize for coherence, not just speed. The best systems gather information in parallel but preserve the order needed for correct interpretation.
The deeper lesson: intelligence is timed judgment
We tend to imagine intelligence as the ability to do more, faster. But real intelligence is often the ability to wait with precision. It knows what can be accelerated and what must remain sequenced. It knows which parts of a problem are independent and which are entangled. It knows that a state is not just a thing that exists, but a thing that becomes meaningful only in relation to what came before and what must follow.
That is why the connection between script loading and state space search is so revealing. Both teach the same hard lesson: the world is not solved by forcing action sooner. It is solved by understanding when action becomes legitimate.
A page loads best when it respects the structure of its own becoming. A search succeeds when it respects the structure of the problem space. And a mind thinks well when it stops asking, “How soon can I act?” and starts asking, “What has to be true before action can be trusted?”
Sources
Hatch New Ideas with Glasp AI 🐣
Glasp AI allows you to hatch new ideas based on your curated content. Let's curate and create with Glasp AI :)
Start Hatching 🐣