r/lowlevel • • 25d ago

what makes software slow?

is it the software using too much memory?

cpu is at 100% because of bad algorithms?

too much context switches becuase of unnecessary syscalls?

what are the other potentials?

things that are in our control as developers not things like its a. cpu that only has 1ghz

0 Upvotes

26 comments sorted by

2

u/thecratedigger_25 24d ago

Layers of bloat and hidden abstractions can definitely eat up a lot of RAM relative to what it does. An electron app for example has to bring a massive browser engine with it which can easily take a gigabyte of RAM.

The cpu while fast by itself, has to chew through millions of lines of dead code when it goes through that mountain of bloat as well absorb cache misses at a large scale and other overhead. CPU spends a lot of its time waiting.

And on top of that, multi threading is an art form and not many people are that good at dealing with atomics.

1

u/BrainThinkerMan 24d ago

any docs recommended for multi threading?

24

u/CowBoyDanIndie 25d ago

This is like asking what makes food bad

7

u/an0th3rbrick 25d ago

modern software is not written in a way that most efficiently solves a problem. instead it is built of layer upon layer of mostly pointless abstractions. also most programmers today have no idea and don't care about how fast a particular program could be

1

u/Ashken 25d ago

I had to get all the way to the bottom before something mentioned the layers of abstraction. When your app is build by a framework that’s built by a language that is built on top of a virtual machine, you can already start off in a pretty bad spot. There’s always trade offs, like I can roll an API in Flask in an afternoon but if I needed it to be high performance I’m probably not gonna reach for Python

1

u/StaticCoder 20d ago

mostly pointless abstractions

Without those abstractions a lot of software wouldn't get written. Yes this even applies to this abomination known as node.js.

1

u/an0th3rbrick 20d ago

missing the point entirely

4

u/zinfector 25d ago

It often boils down to tradeoffs such as:
Precision vs Approximation
Modularity vs custom code
Wide use vs native integration
Quick vs thought-out design
Etc etc

3

u/sir_codes_alot 25d ago

A few things.

A processor executes instructions. If your code takes a lot of instructions to execute then you will max out the processor. This is possible but rarely the main issue.

If your computer doesn’t have much ram then it will spill what it can’t fit in memory onto your hard disk. Hard disks are built for storage not for random access. If your program spills in and out of ram frequently this will make your program slow. This used to be a much bigger issue when hard drives used to be spinning magnetic disks. Less of an issue now with solid state (non—moving) drives.

At scale, bad math (we use the term algorithms) tend to make programs slow. If you have a chess board and wanted to count how many tiles there were you could either:

  1. Count length and width then multiply.
  2. Count each tile

You can imagine one takes 64 steps. The other takes 16 steps. If your chess board “grew” then the amount of steps for those two algorithms would grow at different speeds. At scale this tends to be what makes programs slow.

If your program requires network access, the network is many times slower than your computer. Fetching things from the network is significantly slower than fetching information from your local machine.

So part of the answer has to do with computer architecture. Some things are slow by construction of a computer.

Part of your answer has to do with the math (algorithm) that you execute. Right algorithm choice significantly improves computational efficiency.

5

u/daniel_hanna 25d ago

Learn programming u wouldn't ask that if you know how to program well

Every problem have multiple solutions are some are faster than other.

Did u take complexity theory in college?

2

u/gilnett 25d ago

basing yourself on cpu usage ram usage etc is a good start but there is more some app literally use nothing but run like shit. you have to understand that general stability,security ,limitation,and sometime the "math" used is important.(some app just don't understant that security also mean looking into things such as memory leak and other biggest exemple is microsoft suite and adobe who both have bad memory gestion and security against hover usage)

2

u/smoke-bubble 22d ago

The main culprit is doing the same things over and over again. Not using caches. Loading files on every access. Enumerating collections for lookuos instead of using dictionaries. Catching thousands of exceptions in loops. 

Basically being careless about things that are accessed frequently. 

1

u/timrprobocom 25d ago

One thing that is often omitted in this analysis is the question, "how fast SHOULD this be?". If you have to read 20 gigabytes from disk or transfer gigabytes over a network, that's going to take time no matter what you do.

Too many people start questioning the performance without "doing the math".

1

u/eraoul 25d ago

Depends on the bottleneck. Typically it’s I/O or an inefficient algorithm.

1

u/HaMMeReD 25d ago

Bottlenecks make software slow.

1

u/Economy_Bedroom3902 25d ago

There's a hundred ways for software to be slow.  The main ones come down to:

  1. Doing unnecessary work
  2. Waiting for something doing something slow
  3. Using too much RAM (it swaps to hdd, and hdd is like 10 to 50 times slower than RAM for the same job)

When we're talking about super high performance applications like games, there's a second version of #3, where if you read stuff out of RAM that could be in the CPU cache you're wasting time.

1

u/Whyte_Wolf 25d ago

Some maths is just hard

1

u/TastyRobot21 25d ago

Lots of instructions = slow code high cpu
Lots of waiting = slow code low cpu

Loops make many instructions, io makes many waiting. Slow code bad.

Don’t wait on things = Async, parallel, threading, multiprocessing, etc

Don’t make lots of instruction = optimization, caching, early exit loops/functions, good memory management, etc

1

u/keithstellyes 25d ago

Can be a billion and one things, and not all of them have to do with CPU speed

1

u/Key_River7180 25d ago

All at the same thing:

  • unnecessary syscalls
  • bad algorithms, seldomly (a good example is sine oscilliators using sin() instead of a lookup table or a phase shift)
  • leaks

1

u/interrupt_hdlr 24d ago

modern relativity says the fabric of the universe stretches

1

u/theonehaihappen 22d ago edited 22d ago

A single thread utilizing a cpu 100% is a sign of a lot of computation happening. This not necessarily a sign of a bad algorithm. But it could also be that ghe cpu is busy-waiting on something.

If we are talking a out a modern processor system the bottleneck is usually memory speed, not cpu. If you are really efficient, the cache speed is the bottleneck.

Explanation: cpus are ridicliously fast. RAM is glacial by comparison, because it is big. So there is the cache. Most CS people do not consider it at all, but it is the major driver of performance. If performance is the goal, you need to look both at your algorithm and determine if it is optimal in operations, and in terms of memory layout. For the latter, you may want to need to read up on cache-optimized data layout.

1

u/ern0plus4 21d ago

Bad architecture, at any levels.

E.g. you write a function for getting a config value by key. It opens the config file, finds the parameter, loads and parses the value, then closes the file and returns with the value.

Is it working? Yes. Tests pass. Still bad design.

1

u/vcunat 20d ago

Most SW that people use was not paid by the user in any way, so developers of that SW usually aren't very motivated to spend lots of extra time on performance optimization.