Questions tagged [optimization]

Optimization is the act of improving a method or design. In programming, optimization usually takes the form of increasing the speed of an algorithm, or reducing the resources it requires. Another meaning of optimization is numerical optimization algorithms used in machine learning.

In computer science, program or software optimization is the process of modifying a system to make some aspect of it work more efficiently or use fewer resources. In general, a computer program may be optimized so that it executes more rapidly, or is capable of operating with less memory storage or other resources, or draw less powerWikipedia. Other resources may include disk access, communication bandwidth, video performance and user interface responsiveness.

Common software-related optimization goals are:

  • Design or algorithm efficiency.
  • Source code level. For example Duff's Device.
  • Build level or optimizer flags, often trading build time for run-time efficiency.
  • Compile level; choosing the best compiler.
  • Assembly level. The best machine mapping to a problem.
  • Run time. Examples include virtual machine parameters and profile guided optimization.

Less strictly software-related optimization goals are:

  • Query Optimization. This is the process of improving the design of a database query to increase performance. Use the tag for questions about query optimization.
  • Numerical Optimization. Use the tag for questions about numerical optimization.
  • Teacher/colleague happiness. Writing software in a way that some important person or a group of persons appreciates the code as read by a human, e.g. for clarity and ease of maintenance.

Performance optimization often increases program complexity and reduces its maintainability. Reducing space requirements often means code running slower, while making code run faster often increases its memory demands, although the most profound algorithmic optimization will often improve on both aspects.

A commonly cited peril is "premature optimization" ("the root of all evil", as the saying goes). In contrast, the most dramatic effect on optimization is at the Design Level via algorithm efficiency; this is the earliest stage of development thus seemingly a paradox.

The way to resolve this paradox is to consider the correct order of implementations. Correctness should come first (thus starting with the simplest, most self-evidently correct code), algorithmic improvements second, performance-improving "micro-optimizations" come last. "Premature optimization" means focusing on micro-optimizations right away before even formulating a correct solution (which often leads to altogether wrong, though efficiently so, code); or before considering algorithmic optimizations which, if possible, would obviate those micro-optimizations in the first place.

When using this tag, i.e. asking about optimization, please state the optimization goal you have in mind. The lists above illustrate that many possible optimization goals are mutually exclusive (e.g. performance vs simplicity / maintainability). It is hence not possible to optimize for everything; and optimizing without a clear goal is another common peril and makes a question too broad or unclear.

See also:

38871 questions
13
votes
1 answer

R nlminb What does false convergence actually mean?

I'm using the function nlminb to maximise a function and got convergence (convergence =0 ) with the message false-convergence. I tried the documentation but no answer. I tried to get the port documentation on the function and could find the function…
DJJ
  • 2,481
  • 2
  • 28
  • 53
13
votes
2 answers

Fast undo/redo for bitmap editor when memory is limited?

I'm trying to write a bitmap editor for a mobile device (i.e. a limited version of Photoshop). The user's document consists of ~4 bitmaps around 1000x500 in size each. I want a robust and efficient undo/redo system that's as simple as possible. I'm…
memcom
  • 635
  • 1
  • 5
  • 10
13
votes
9 answers

in PHP, which is faster - reading a file or a database call?

I've a web app built in PHP with Zend on a LAMP stack. I have a list of 4000 words I need to load into memory. The words have categories and other attributes, and I need to load the whole collection every time. Think of a dictionary object. What's…
Corey
  • 1,977
  • 4
  • 28
  • 42
13
votes
5 answers

Converting a 1.2GB list of edges into a sparse matrix

I have a 1.2GB list of edges from a graph in a text file. My ubuntu PC has 8GB of RAM. Each line in the input looks like 287111206 357850135 I would like to convert it into a sparse adjacency matrix and output that to a file. Some statistics for my…
Simd
  • 19,447
  • 42
  • 136
  • 271
13
votes
4 answers

Pyspark socket timeout exception after application running for a while

I am using pyspark to estimate parameters for a logistic regression model. I use spark to calculate the likelihood and gradients and then use scipy's minimize function for optimization (L-BFGS-B). I use yarn-client mode to run my application. My…
panc
  • 817
  • 2
  • 14
  • 30
13
votes
4 answers

How does memory reordering help processors and compilers?

I studied the Java memory model and saw re-ordering problems. A simple example: boolean first = false; boolean second = false; void setValues() { first = true; second = true; } void checkValues() { while(!second); assert…
13
votes
4 answers

Editing array to ensure strictly increasing values

Consider a sorted vector x that is bounded between min and max. Below is an example of such x where min could be 0 and max could be 12: x = c(0.012, 1, exp(1), exp(1)+1e-55, exp(1)+1e-10, exp(1)+1e-3, 3.3, 3.33333, 3.333333333333333, 3+1/3,…
Remi.b
  • 17,389
  • 28
  • 87
  • 168
13
votes
4 answers

Bit popcount for large buffer, with Core 2 CPU (SSSE3)

I'm looking for the fastest way to popcount on large buffer of 512 or more bytes. I can guarantee any required alignment, and the buffer size is always a power of 2. The buffer corresponds to block allocations, so typically the bits are either all…
Matt Joiner
  • 112,946
  • 110
  • 377
  • 526
13
votes
1 answer

Why Hibernate sometimes ignores FetchMode.JOIN?

I have an entity with a @ManyToOne relation, which I'd like to retrieve with a single query, thus using @Fetch(FetchMode.JOIN). Sometimes Hibernate doesn't respect that and issues N+1 SELECTs. With sometimes I mean that since I don't know what…
Giovanni Lovato
  • 2,183
  • 2
  • 29
  • 53
13
votes
8 answers

How to check which stored procedure is taking maximum time in sql server

I want to know what are various methods by which I can monitor which of my stored procedure's and SQL queries are taking more time on various components(CPU cycle, scan time etc.) than already set threshold value. I want it to be logged as…
Shantanu Gupta
  • 20,688
  • 54
  • 182
  • 286
13
votes
3 answers

Flipping sign on packed SSE floats

I'm looking for the most efficient method of flipping the sign on all four floats packed in an SSE register. I have not found an intrinsic for doing this in the Intel Architecture software dev manual. Below are the things I've already tried. For…
nsanders
  • 12,250
  • 2
  • 40
  • 47
13
votes
7 answers

Does the c# compiler optimizes Count properties?

List list = ... for(int i = 0; i < list.Count; ++i) { ... } So does the compiler know the list.Count does not have to be called each iteration?
Vitaliy
  • 141
  • 2
13
votes
1 answer

Optimization Break-even Point: iterate many times over set or convert to list first?

Here's something I've always wondered about. I'll pose the question for Python, but I would also welcome answers which address the standard libraries in Java and C++. Let's say you have a Python list called "my_list", and you would like to iterate…
Paul Siegel
  • 1,401
  • 13
  • 36
13
votes
10 answers

Performance-wise: request JSON and render in JS, or request the entire HTML?

Possible Duplicate: Why is it a bad practice to return generated HTML instead of JSON? Or is it? IF I send an AJAX request to a PHP file, what would result in faster rendering of HTML: Sending the completely formatted HTML straight from PHP,…
yanayz
  • 163
  • 2
  • 8
13
votes
4 answers

How can GCC unroll a loop if its number of iterations is unknown at compile time?

I was reading the optimization options for GCC when I found the option -funroll-all-loops. Its description reads: Unroll all loops, even if their number of iterations is uncertain when the loop is entered. This usually makes programs run more…
PC Luddite
  • 5,883
  • 6
  • 23
  • 39
1 2 3
99
100