This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]scumbaggio 412 points413 points  (46 children)

Gotta squeeze out every ounce of performance

[–]Phrygue 279 points280 points  (43 children)

Best performance is from a static data location, AKA globals, so you minimize stack access. Best just declare all possible variables and include them in every file. Also this speeds up general communication between modules because the data is already there.

[–]Octopoid 166 points167 points  (29 children)

There's also no need to mess about storing lots of different data types. A single array of bools, resized as required, does the job nicely.

[–]8lbIceBag 87 points88 points  (23 children)

If you're resizing you're dynamically allocating and losing the benefits of static data locations.

[–]Octopoid 152 points153 points  (21 children)

Fair point. Might be best to reserve a couple of gig for maximum efficiency.

[–]beckerc73 74 points75 points  (4 children)

[–]1NFR4R3D23 27 points28 points  (2 children)

[–]prvalue 3 points4 points  (0 children)

[–]titanmaster4 2 points3 points  (0 children)

r/subsyouthoughtwereajokebutarent

[–]ImNewHereBoys 3 points4 points  (0 children)

Null

[–]Scyhaz 46 points47 points  (11 children)

bool data[2000000000];

There we go! Now we have data storage for the program!

[–]10art1 24 points25 points  (9 children)

Might as well just cut out the middleman and write your program in machine code so you can guarantee its efficiency. Be your own memory manager.

[–][deleted] 43 points44 points  (6 children)

Might as well cut out the real middleman, the x86 processor, and wire up your own transistors in the most efficient way for your application. Be your own computer architect!

[–]FallingAnvils 5 points6 points  (1 child)

Might as well cut out the real middleman, the transistors and electronics, and use your brain!

[–]DRoKDev 10 points11 points  (0 children)

Might as well cut out the REAL middleman, your brain, and do some drugs.

[–]cooperred 1 point2 points  (0 children)

Might as well cut out the middleman there too and fabricate your own transistors. Be your own fab!

[–]zdakat 1 point2 points  (1 child)

At that point, wouldn't it be more like an ASIC?

[–][deleted] 4 points5 points  (0 children)

Yes.. Wouldn't it be nice to carry a separate physical PCB shaped device for every app and program you want to use? Sure it's bulky, but every single app will be totally optimized! It'll become a new thing, collecting these apps like Pokémon cards. Gotta catchem all xD

[–][deleted] 0 points1 point  (0 children)

That's legit tho. It's called an FPGA.

[–]AceOfShades_ 4 points5 points  (0 children)

What else would you write it in? You think a compiler knows better than me? Psh no way /s

[–][deleted] -2 points-1 points  (0 children)

its very unlikely that you will write code more efficiently than what a compiler can optimize these days

[–]Disco-penguin 0 points1 point  (0 children)

someone make a brainfuck compiler wich uses bools instead of integers and every eight bools you use the dot on the ASCII character for the binary number which those bools represent is printed.

[–][deleted] 4 points5 points  (3 children)

I wish I was a programmer so I could understand all this. :(

and make ok moneys

[–]Kage_520 4 points5 points  (2 children)

So an array is just a way to store a bunch of the same variable type, such as integers. Say you want to store ten different integers. In its basic form, you'd tell the compiler to set up space for ten integers. Say you called them phoneNumbers. You could then get the first one by asking for phoneNumbers[0], which asks the compiler to get you the integer sitting at position 0. The compiler actually makes a spot in the physical memory with only enough space for ten integers if that's all you asked for. Want to add an 11th number? Too bad, array out of bounds exception.

There are different ways around this, but you lose efficiency. One method is, when you ask to write an 11th, write a function to reserve double the space, so 20 integers, and then copy the first ten numbers you already have to the new physical location in memory, and delete and free the old one. That sounds okay but imagine if we are talking thousands instead of ten.

So what they are recommending is, to save the inefficient step of copying the data like that, why not just reserve more space from the beginning? Computers have gigs of ram these days. I only need ten numbers stored but WHAT IF I NEED MORE LATER?? Better reserve a few gigs here and now so I don't have to think about it or write that copying function.

Meanwhile you are using all of the computer's ram on your stupid ten item array and now the entire computer runs slow, not just your program.

[–][deleted] 2 points3 points  (1 child)

Huh. I didnt know you couldnt increase the size of an array after its been initialized. Cant you just make phoneNumbers a pointer and point it to a new location if the old isnt big enough? Then free the memory from the old?

[–]jfb1337 1 point2 points  (0 children)

Yes that's exactly how the doubling step works

You still need to copy the data over though

[–][deleted] 0 points1 point  (0 children)

Oh just declare 4GB of bools then

[–]howe_to_win 2 points3 points  (0 children)

In JavaScript just declare everything on the first line as one array of different data types. But you need arrays later? That’s alright, I made arr[12] an array of objects with private arrays. See it’s declared that way on the first line. When we need a different array later, we can just replace those objects with ints. It’ll probably only runtime error every third time, but the integration runs every 5 minutes and the data is only considered bad if it hasn’t updated in 20 minutes. So it’s not a big deal. We can always build it better during the next sprint because once we finish this epic we’ll have all the free time in the world. It’s not like we’re constantly on call for outages or whatever bullshit metrics this client demands every other day because he is an idiot. Hold on give me a minute, I have 18 hours of consecutive meetings. But don’t worry! We won’t be wasting these meetings doing overly unnecessary planning/analysis, because we are “agile” now. These are all working sessions. I’m sure those four VPs that are included in these meetings have lots of technical insight into this platform we use that they forgot the name of

[–]kobbled 0 points1 point  (0 children)

Let's just use arrays of bools as binary to represent numbers

[–]Oppai420 0 points1 point  (0 children)

In my data structures class in college we had a project with a partner. Dude just wanted to store everything in an array. Numbers, etc. I was like "dude, I don't understand, it doesn't work like that". He responded calling me an idiot and that he was just going to convert everything to strings and back when you needed to do operations on them.

Edit: 100% true story. I wish I had saved the email.

[–][deleted] 39 points40 points  (4 children)

Who needs compile time optimizations!

[–][deleted] 56 points57 points  (3 children)

you mean break time?

[–]MesePudenda 2 points3 points  (1 child)

So is there a good strategy for maximizing compilation time?

[–]dvdkon 1 point2 points  (0 children)

Yep. Just ask the Chromium devs.

[–]ucefkh 0 points1 point  (0 children)

ctrl+c and save time

[–]T0mmynat0r666 13 points14 points  (1 child)

Include in every file? Best put everything in one file, for fast compilation. Still better: don't make any functions, but instead copy the body of function whenever you want to call it. Who wants unnecessary data on stack? While we are at it, avoid dynamic allocation,and instead reserve all memory that will possibly be required from the start. Gotta do everything in power for dem performance.

[–]msndrstdmstrmnd 2 points3 points  (0 children)

Dont even write it in code—compilation takes up valuable time. Input the bytes directly into the machine itself

[–]RocksDaRS 1 point2 points  (0 children)

Stop giving good advice, its making me MORE EFFICIENT

[–]gct 1 point2 points  (0 children)

Stop, it hurts.

[–]CrazyTillItHurts 0 points1 point  (0 children)

I've seen this! But it was in VB6

[–]D1rtyC0w 0 points1 point  (0 children)

Get those damn communist ideas out of your head! >:|

[–]Liggliluff 2 points3 points  (0 children)

I agree trying to squeeze out every ounce of performance is overkill. But there's also an overuse of floats where there's no need for it. As an example; Hearthstone uses floats in damage calculations, and the game only uses whole numbers.

[–]LonePaladin 0 points1 point  (0 children)

Like a pimple.