This is why you optimize code (Particles v6)

The following is a a picture of me creating 1000 particles instantly. A blue explosion from fully physically simulated particle code. This is 1.5 times faster than my last version, which is 6 times faster than my first version.



Click on the image for 60 fps.

Anyway, this is what I feel particles should be like if ROBLOX ever implements them.

1 Like

You should share this. We like when you share things.

Would you please make a place where we can check this out in-game?

I take a drink every time I see the word optimize on this site.

Optimizing is perfectly fine. The problem comes when people post “omg why are your variables not local!! it’s 10x faster!!!” on a help thread or some other random place - in nearly all cases one more table index in anything other than a tight loop will not change anything, and if that is a deciding factor make the changes once you begin hitting that as a bottleneck. Optimizing is perfectly fine. Premature optimizing isn’t.
(sorry about ranting. im bitter.)
(also sorry golly’s liver)

Are you scared of having games that look good and run at 60 frames per second? Because with out optimization that wouldn’t be possible.

Optimization =

Interacting with ROBLOX as little as possible.
Casting as few rays as possible
Using Vector3 as little as possible
Simplifying math as much as possible.

See chc4’s post - many of us aren’t doing anything that optimization has a significant impact on.

I just wanted to see pretty things. Why you all gotta argue about it!

Cool explosions though.

[quote] I just wanted to see pretty things. Why you all gotta argue about it!

Cool explosions though. [/quote]

Thank you!

But anyways, I don’t understand people’s aversion to writing code that runs well. And I don’t see why people think that “optimize” means “make it unreadable and or hard to use.”

Thats really cool. I don’t know why you people are being so nasty about this…

That’s amazing, is there every a chance where you make it free source for people to learn from it? :c

It’s all about that Big O notation.

The reason I use local variables is because it makes variables look nice when written.

It took me a while to discover that localisation actually makes things faster. I used to think it was the exact same, and that it was just an aesthetical difference in writing code.

[quote]
Optimization =

Interacting with ROBLOX as little as possible.
Casting as few rays as possible
Using Vector3 as little as possible
Simplifying math as much as possible. [/quote]

Question: I often struggle on whether or not I should optimize the internals of my RTS game, the heavy math section, I move all my units by CFrame, and I optimized it as much as possible while keeping it clean, but if I would optimize it more, I doubt anyone but us two- and I heard of possibly another- could even understand it, much less after hours of reversing the manually broken down math functions. It just seems like a sin to go any further, although my game probably would get a ~10% efficiency boost from it (something my players would love) it would permanently turn my math code into a taboo for the person who will inherit my game

[quote]
Optimization =

Interacting with ROBLOX as little as possible.
Casting as few rays as possible
Using Vector3 as little as possible
Simplifying math as much as possible. [/quote]

Question: I often struggle on whether or not I should optimize the internals of my RTS game, the heavy math section, I move all my units by CFrame, and I optimized it as much as possible while keeping it clean, but if I would optimize it more, I doubt anyone but us two- and I heard of possibly another- could even understand it, much less after hours of reversing the manually broken down math functions. It just seems like a sin to go any further, although my game probably would get a ~10% efficiency boost from it (something my players would love) it would permanently turn my math code into a taboo for the person who will inherit my game[/quote]

Remember about comments. Just note what you smash together.

[quote]
Optimization =

Interacting with ROBLOX as little as possible.
Casting as few rays as possible
Using Vector3 as little as possible
Simplifying math as much as possible. [/quote]

Question: I often struggle on whether or not I should optimize the internals of my RTS game, the heavy math section, I move all my units by CFrame, and I optimized it as much as possible while keeping it clean, but if I would optimize it more, I doubt anyone but us two- and I heard of possibly another- could even understand it, much less after hours of reversing the manually broken down math functions. It just seems like a sin to go any further, although my game probably would get a ~10% efficiency boost from it (something my players would love) it would permanently turn my math code into a taboo for the person who will inherit my game[/quote]

First of all, determine if it even needs to be optimized.
local ExpectedTimeOfCompletion=1/60
local st=tick() --Start time
–Run some of your code through here, worst case
print((tick()-st)/ExpectedTimeOfCompletion)

if the code runs once per frame, then the expected time of completion is 1/60

If what prints out it greater than 0.5, then you might want to think about optimizing.

And if it’s only 10%, don’t make your code into taboo.

Also, make comments. Even small ones help.

–Last Local Position
–Other variables
–Connections
----Frame And Properties----
–If there is not a spare frame, then make a new one.
–Store the visible value of the frame for faster access.
----Updater Function----
–Deletion check
–Physics Update
–WindResistance Multiplier
–If it’s fast, then make it bounce better. Otherwise have it conserve energy.
–Render Update
–RelativePosition
–CurrentLocalPosition
–Calculate Intersection with camera plane and convert to Plane Coordinates
–Calculate Intersection with camera plane and convert to Plane Coordinates
–Convert to Plane Coordinates
–Convert from Plane Coordinates to Pixel Coordinates
–Calculate Length
–Calculate Size and Transparency
–Update Frame
–Check to see if it’s reasonably visible
–User control functions
–Faster for small number of removes.