Settings

Theme

Ask HN: Which line of code you have written will be executed the most?

11 points by jamesmstone 6 years ago · 20 comments · 1 min read


The other day I was trying to determine which line of code I have written will get run the most?

I think for me it would be a for loop in a cron job I run on work's servers - not very exciting! I am sure HN has many more interesting examples.

maybe you have written code:

- deep in an OS that handles memory management?

- that is deeply distributed?

- that is in every JS lib? ~~cough cough left pad cough~~

- maybe it is an accidental infinite loop you once wrote?

akg_67 6 years ago

20+ years ago, I wrote the Fortran code that polls the vibration of a turbine shaft every 1/100th of second. That facility is still in operation, the system I worked on is still in operation, those type of facilities run 24x7x365 and rarely have a downtime where system or turbine might be taken offline for long. I guess my code has been running every 1/100th of second for 20 years or so. I don't think I can write any code that will beat that little piece of code in frequency of use.

uberman 6 years ago

At a fortune 100 company I consulted at, developers were rewarded for writing efficient code that was frequently reused. This was literally micro-transaction recognition and rewards a decade prior to anything resembling today's micro-transaction cloud billing.

I wrote the billing/logging system and I am certain the main "method call logger" is by far the most frequently executed code I have ever written. It was called by any method that the author wanted to be compensated for. Alas, I was not allowed to include the call to this method in the compensation pool :-(

seanhunter 6 years ago

I spent a week or so pouring through valgrind and profile output optimising the very heart of the code for a Monte Carlo simulation at a major investment bank. Some of the lines of code I wrote in that week will have been executed billions of times per day since I pushed them back in 2007 or so. They are still being used.

I got a good overall speedup (over 5% in code that was already pretty well-optimised) but by far the most valuable optimisation I did was one of the most basic - hoisting variables out of for loops. This kind of thing

    for(int i=0; i<something; ++i) {
       int x=0;
       //...do something with x  
    }

changes to...

    int x;
    for(int i=0; i<something; ++i) {
       x=0;
       //...do something with x  
    }

There are slightly more subtle versions of that, but at the time none of the compilers we were using (gcc 3.2, solaris 8 C++ compiler or Visual C++ 7) could optimise that without you doing the hoist yourself.
dave_sid 6 years ago

// TODO

newswasboring 6 years ago

For me it has to be the data analysis pipeline I wrote for one of the biggest semiconductor manufacturing fabs in the world. Its is triggered for every lot they produce (a lot is usually 25 wafers). This company holds the majority market share in semi manufacturing space, so it is more than coin flip likely that the device you are using to read this contains a chip which was analyzed by my pipeline. (So if it breaks due to thermal issues... sorry).

mod 6 years ago

I wrote the backend for a large saas that is in the business of pushing notifications to ios, Android, and browsers.

It's not as cool as being a frequent call at the OS level, but pretty good for an ex web developer.

I think it's very likely still in use, in some part, and surely into the billions of deliveries, so who knows how many executions of some inner loops or whatever.

quickthrower2 6 years ago

Probably some code I wrote to see how long a for loop would take in js looping a billion times. Not too exiting either

austincheney 6 years ago

On the front end it’s some code that walks the DOM in a way the standard DOM don’t. It can get DOM nodes by node type. On the backend it’s some code that walks the file system for systems automation.

Simple primitive stuff like that tends to get embedded in a variety of other automation.

eb0la 6 years ago

I guess mine is a type-conversion class inside an apache beam job. Usually it's running on a streaming job; but when you launch it as dataflow batch job it has 30-40 workers running it at once for several hours.

rl3 6 years ago

Technically: it's things inside of rendering or sim loops.

Philosophically: print debugging.

qlk1123 6 years ago

Some architecture-dependent things in context-switch/signal handling path.

longcommonname 6 years ago

Rewrote a logging framework that logged petabytes per day.

scott31 6 years ago

if err != nil {

joezydeco 6 years ago

Lots of interrupt and timer tick handlers. The early ones ran every 500 microseconds and those went out the door 25 years ago.

luhego 6 years ago

A decorator that checks if the user is logged before running a GraphQL mutation.

@login_required

def mutate(...):

nxpnsv 6 years ago

    import numpy

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection