Voorkom voortijdige optimalisaties

An article, posted 1 day ago filed in javascript, programming, premature, optimalisatie & tijd.

Voortijdige optimalisatie, of premature optimisation, is een bekende neiging van veel software ontwikkelaars. Het is een idee verbonden aan Donald Knuth:

> We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil. Yet we should not pass up our opportunities in that critical 3%

Veel ontwikkelaars halen eer uit het maken van "slimme" oplossingen die het draaien van de code net een beetje sneller zouden kunnen maken. De nadruk ligt op zouden omdat het veelal niet gebaseerd is op het daadwerkelijk meten aan de applicaties. Slechts door het applicatiegedrag goed te monitoren kunnen de échte performance problemen geïdentificeerd worden.

Erger is dat er kosten verbonden zijn aan zulke voortijdige optimalisaties:

  1. Het kost vaak extra tijd om een feature op te leveren (wat mij betreft niet het ergste)
  2. Het levert vaak code op die minder i…

Blog concept: Sketchy optimisations

An article, posted about one year ago filed in activerecord, database, optimization, orm, performance, premature, query, rails, software & sql.

Recently a colleague was showing me a concept he was working on. He drafted a change in a fight against so-called 1+n-queries (actually for some reason unknown to me they're called n+1 queries, but my head isn't able to process the problem with just one more query after n queries…); in software development using ORMs like active record it is quite easy to make a single database request objects that when a presented within a view trigger other queries for every object because it has a relationship. Round trips to databases are generally bad as they take time.

For his change, he introduced a new class that we could seemingly reuse, with a just another (a bad code-smell) declaration of relations between objects and whether these should be preloaded when retrieving the primary object. This was in response to indeed a quite bad part of our code that entailed returning objects with counts of selected associations, but instead of counting these in the database, the current code was a…