Optimization is the process of improving an existing program to make it work more efficiently or/and using less resources.

learn more… | top users | synonyms (1)

12
votes
11answers
2k views

How do I know if the compiler broke my code and what do I do if it was the compiler?

Once in a while C++ code will not work when compiled with some level of optimization. It may be compiler doing optimization that breaks the code or it may be code containing undefined behavior which ...
40
votes
7answers
7k views

In software programming, would it be possible to have both CPU and GPU loads at 100%?

This is a general question on a subject I've found interesting as a gamer: CPU/GPU bottlenecks and programming. If I'm not mistaken, I've come to understand that both CPU and GPU calculate stuff, but ...
0
votes
0answers
13 views

Coerce optBlock in AlgDesign R package to only show certain treatments per row of blocks

Using the optBlock function of the AlgDesing R package, I can create a block design with 16 treatments, 12 blocks (columns), and 4 treatment per block (rows) with the following code: optBlock(~.,...
4
votes
1answer
88 views

Do I need to declare a delay timer variable as volatile even if I access it from another module

This is a question more about using volatile to prevent optimization than about caching write/read of a variable. Particularly timer delay variables since I don't want to declare everything volatile ...
6
votes
5answers
368 views

Can a pimpl variation be implemented without any performance penalty?

One of the issues of pimpl is the performance penalty of using it (additional memory allocation, non-contiguous data members, additional indirections, etc..). I would like to propose a variation on ...
6
votes
0answers
223 views

What lambda function optimizations, if any, are planned for Java 9 and beyond?

I'm working on a high-performance project where Java 8's lambda functions are enormously useful. I've found, however, that they're memory inefficient when used en masse. For example, suppose I need to ...
61
votes
18answers
3k views

Why should I care about micro performance and efficency?

Many questions and answers on the C/C++ pages, specifically or indirectly discuss micro performance issues (such is the overhead of an indirect vs direct vs inline function), or using an O(N2) vs O(...
5
votes
3answers
155 views

Do Javascript minifiers optimize for gzip?

Case1: There are two snippets of code that are very similar and very gzip-able, one at the start of the document and the other is beyond 32kb at the end of the document. Does the minifier bring the ...
0
votes
0answers
32 views

Optimal Simplification of Transposition Products

I am looking to take a product of a large number of transpositions, and boil it down to a smaller number of products. I have the following code, and would like some input on efficient ways to boil ...
2
votes
1answer
55 views

Pre-computation strategies when solving multiple linear equations with the same matrix?

Often in modeling, data processing, and optimization; the intensive portions of the code can often reduce to solving a lot of linear equations. e.g. solve for x1 in A x1 = b1 solve for x2 in A x2 =...
-2
votes
0answers
196 views

Is early optimization the root of much evil? [duplicate]

I believe that perfomance optimization must start as soon as possible. I think that the classical reasons to put it off are fundamentally wrong. The main points why the optimization activity has to ...
0
votes
0answers
13 views

Latency in creating configuration in apache commons configuration

I am planning to use Apache commons configuration (https://commons.apache.org/proper/commons-configuration/) to merge various configuration files. Since for me, the configuration file names are ...
3
votes
5answers
110 views

Use Exceptions for control flow in order to increase performance?

I add a lot of elements to a list of lists. If the list of lists my element should be saved to, does not exist yet, I handle this by catching an exception and adding a new list to my list of lists. ...
6
votes
5answers
384 views

Is it wise to rely on optimizations?

Should I write my code to be clear what I am doing and rely on the optimizer to clean up my code efficiency, or should I be obsessive about getting every last ounce of power out of my code? And how ...
0
votes
0answers
20 views

How to calculate a lookup table index from comparing 3 variables treating equality as distinct cases

My code needs to use different lookup table values depending on the relative order of 3 simple input numeric variables a,b,c. If any of a,b,c are equal that's considered a distinct case. I'm looking ...
5
votes
5answers
271 views

My brute force solution is too slow, needed DP solution [closed]

Concise problem definition: given n and {a,b,c}; (1 ≤ n, a, b, c ≤ 4000); Constraint -> a*i + b*j + c*k==n (i,j,k>=0); Objective-> maximize(i,j,k) Examples: n=47 and a=7,b=5,c=8 -> ...
1
vote
1answer
47 views

The optimal way to reschedule appointments

Let's say I have the following appointments: Appointment 1 = 1:00 Appointment 2 = 2:00 Appointment 3 = 3:00 Appointment 4 = 4:00 I need to reschedule all of these one hour later: Appointment 1 = 2:...
25
votes
11answers
2k views

How to deal with misconceptions about “premature optimization is the root of all evil”?

I've encountered many people who are dogmatically against anything which can be considered "optimization" in the general English-language sense of the word, and they very often quote verbatim the (...
4
votes
1answer
138 views

Word ladder efficency problem

I have a problem dealing with word ladders. The problem is: given two words and a dictionary file, find the shortest word ladder between the two words. So if given the words cat and pot: cat -> ...
1
vote
1answer
84 views

Recieving errors without engaging in excessive communication when using sockets

I'm currently writing a program that communicates with a server over TCP sockets. I originally planned for the communication to include a message confirming successful communication at the end of ...
1
vote
1answer
79 views

Clairvoyance in caching - optimal strategies?

This question relates to the question here, but I'll generalise it so that you can answer effectively without reading all of that. Context: Imagine you had a large set of data greater than your ...
4
votes
3answers
364 views

Work out which parcel deliveries we ship ourselves and which we outsource

Firstly, I hope I'm asking this in the right place. I work for a large online retailer in UK. We ship approaching 2000 orders each day and are growing very quickly. We currently use multiple delivery ...
21
votes
5answers
14k views

JIT compiler for C, C++, and the likes

Is there any just-in-time compiler out there for compiled languages, such as C and C++? (The first names that come to mind are Clang and LLVM! But I don't think they currently support it.) ...
2
votes
1answer
59 views

How to optimize a bloated entity that causes a huge query

I have an application that exposes a series of Web services. One of my entities has a bunch of one-to-many and many-to-many relations to other entities. My transactionality level is at DAO, and I'd ...
3
votes
0answers
154 views

How to distribute a number of elements in a bucket so that it is within a range?

I have 50 elements n1, n2, n3, ... , n50 and a limited number of buckets, say 5 buckets and each bucket can hold a range from, say 100 to 150 only (which is nothing but the sum of the elements in that ...
2
votes
4answers
95 views

How does a query execution plan affect query execution?

I have read some articles on SQL Server query optimization. The point I get is SQL Server generates a query execution plan for each stored procedure when it's executed for the first time. Those ...
5
votes
1answer
237 views

Combinatorial Optimization: Filling a Bag with Sand

I have an interesting "real-world" combinatorial optimization problem that I need to solve programmatically, however I have yet been able to whiteboard a good strategy. The task is similar to the ...
0
votes
1answer
42 views

python snippet optimization explanation

I'm attempting optimize and figure out why for input n a function I wrote f(n) appears to never finish executing when n > 26. TL;DR I need to figure out how to find the complexity of various python ...
0
votes
0answers
58 views

Using counter or constant for parameter position

Suppose that I have the following Java code: int i = 0; PreparedStatement statement = con.prepareStatement("SELECT * FROM table " + "WHERE field1 = ?, field2 = ?, field3 = ?..."); statement.set**...
2
votes
3answers
138 views

Is denormalising a data structure essentially a code optimisation, to which the normal rules apply?

One of Bloch's Effective Java items 55: Optimize judiciously extends Jackson's rules on optimization: Rule no. 1: Don't optimise! Rule no. 2 (for experts): Don't optimise yet! Extra ...
0
votes
1answer
187 views

Approaching Particle Swarm Optimization with optimization problem, how to use PSO with it?

I am learning Particle Swarm Optimization. The problem is to find the pair of number whose sum is lowest. Lets say we have some numbers z1,z2,z3,z4 Number Value z1 -2 z2 -3 z3 3 ...
0
votes
0answers
84 views

Decision making algorithm

I'm currently solving an optimisation problem of my own design, just to experiment and learn a little something. Here's the concept: I have a user that starts at home. The objective of this user is ...
0
votes
1answer
140 views

Are there compilers which optimize the use of mathematical functions?

Today while programming I stumbled upon the following question - are there any compilers which optimize based on mathematical assumptions? For instance in cases like unsigned int i,b; (i,b not ...
0
votes
3answers
77 views

How to optimize iterable queries with external arguments

I will use C# here as an example, but my question is about any language. My question is from framework to compiler perspective (i.e the solution can be by implementing given idea inside compiler) ...
2
votes
1answer
139 views

Maximizing Value and Volume, minimizing weight - Knapsack

Trying out a Knapsack variant where the rules are Any item you take must fit completely in the bag Usable metrics of the bag are length(l),width(w),height(h) and you can assume that if the products ...
0
votes
2answers
158 views

Optimization problem where to start, what algorithms to use? [closed]

I have an optimization problem and I was wondering where to start from to be able resolve it. I think it can be solved with an NP-complete algorithm but I am not sure where to start from. The problem ...
2
votes
1answer
113 views

Improving sampling algorithm

I am having a bit of trouble designing a new feature at the moment. It is part of a resource management system. I was wondering if anyone has experience doing anything similar. I'll try to explain: ...
3
votes
3answers
127 views

What can qualify for potential tail call recursion (TCO) optimization or tail recursion elimination (TRE)

Short question is: what can qualify for potential tail call recursion optimization (TCO) or tail recursion elimination (TRE) if the compiler or interpreter supports it. The summary of this question ...
65
votes
12answers
3k views

When is optimization not premature and therefore not evil?

"Premature optimization is root of all evil" is something almost all of us have heard/read. What I am curious what kind of optimization not premature, i.e. at every stage of software development (high ...
2
votes
0answers
79 views

Program to select N integers with constraints [closed]

I need to write a program which takes 4 inputs as follows N = The number of integers to be generated (10 < N < 10000) Start = The minimum value of the integers (100 < Start) End = The ...
117
votes
17answers
25k views

Is premature optimization really the root of all evil?

A colleague of mine today committed a class called ThreadLocalFormat, which basically moved instances of Java Format classes into a thread local, since they are not thread safe and "relatively ...
4
votes
2answers
225 views

Can profiling be used to verify if optimization was successful?

I know that profiling is useful to identify bottlenecks and determining what parts of the code require how much time to execute. The latter isn't always very easy to track in the midst of other paths ...
3
votes
1answer
138 views

How to safely and cheaply delete a directory's contents that are constantly being deleted/overwritten

I'm coding something that will check a specific static location's directory, and if it exists, and a certain process has not run in n minutes, it deletes that directory's files and all sub-directory ...
9
votes
10answers
528 views

How often is software speed evident in the eyes of customers?

In theory, customers should be able to feel the software performance improvements from first-hand experience. In practice, sometimes the improvements are not noticible enough, such that in order to ...
10
votes
4answers
6k views

Data Oriented Design - impractical with more than 1-2 structure “members”?

The usual example of Data Oriented Design is with the Ball structure: struct Ball { float Radius; float XYZ[3]; }; and then they make some algorithm that iterates a std::vector<Ball> ...
1
vote
2answers
835 views

How to measure algorithm accuracy?

I have a few optimization algorithms (for finding function minimum) and I'd like to check how good they are. Suppose I build test cases and compare the actual results to theoretical ones. What ...
-1
votes
1answer
103 views

Sorting an array based on another array's order, quickly [closed]

There are two arrays of maps. The first array contains maps of ID values in a specific order (but not necessarily either pure ASC or DESC ordering): // pseudo code first := [ {"id": 1}, {"...
0
votes
1answer
121 views

Optimization: How much time saved is considered worth it? [closed]

I was reading up about branch predictions and cache misses, and have decided to read what every programmer should know about memory. But I'm not sure how much low level knowledge do I need to have to ...
2
votes
2answers
911 views

How is switch/case handled as to avoid comparisons to the case values?

I've read in multiple answers that switch/case avoids "unnecessary" comparisons, but I never learned this in college, and I'm a little stumped on how the program would figure out which case to jump to ...
136
votes
31answers
15k views

Is micro-optimisation important when coding?

I recently asked a question on Stack Overflow to find out why isset() was faster than strlen() in PHP. This raised questions around the importance of readable code and whether performance improvements ...