I’m currently in a low level C class, but I program Javascript as my job.
Here are a couple C optimizations/Problem areas my book has gone over so far (Just started so I don’t have much):
- Procedure overhead (restoring registers, creating the stack, etc.)
- Sometimes creating temporary variables instead of reading/writing to memory in loops.
Additionally how much time can be spent ‘optimizing’ Javascript? C is compiled down to machine code and much more time can be spent on compiling an executable. How much time is spent in a typical JS compiler optimizing?
Javascript is a higher level language than C and because of that I don’t actually ‘know’ what is going on underneath. What optimizations should I worry about? Will what I am learning now in C also apply in Javascript?
Javascript and C have such radically different ways of expressing things that I doubt one could even compare the optimization techniques.
For this post, I’ll just look at the optimizations the programmer can make:
C:
mallocand choosing when to free memory and when to reuse it.Javascript:
nullJust as a quick example. The two really are worlds apart, so I’d have to simplify optimization techniques down to:
The last item on the list is, as far as I am concerned, the most import bit of optimization that any coder can learn how to do.
Disclaimer: Yes, I know the old adage of ‘Premature optimization is the root of all evil.’ Choosing a smart, or at the very least, not terribly dumb way to solve a problem is not premature..