optimization

"Conditional Conditions" in a WHERE clause (Which condition to apply depends on a "mode" flag)

I have a situation which I have solved in two different ways, but was wondering what people thought about the options, and if they have any other alternatives... The system is processing "intervals" of data. All the data is allocated to an "interval" The interval is represented by an "interval_start" DATETIME in the Fact table A...

When to switch from unordered lists to sorted lists ? [optimization]

I have to implement an algorithm to decompose 3D volumes in voxels. The algorithm starts by identifying which vertexes is on each side of the cut plan and in a second step which edge traverse the cutting plan. This process could be optimized by using the benefit of sorted list. Identifying the split point is O log(n). But I have to mai...

How to refactor, fix and optimize this character replacement function in java

While tuning the application, I found this routine that strips XML string of CDATA tags and replaces certain characters with character references so these could be displayed in a HTML page. The routine is less than perfect; it will leave trailing space and will break with StringOutOfBounds exception if there is something wrong with the...

MSSQL JOIN ON GROUP BY is too slow

I have the following query in MSSQL SELECT TOP 50 CustomerID FROM Ratings WHERE CustomerID != 915 AND MovieID IN (SELECT DISTINCT MovieID FROM Ratings WHERE CustomerID = 915) GROUP BY CustomerID ORDER BY count(*) DESC It is super fast. When I try to use it in a subquery like this. SELECT * FROM Ratings WHERE MovieID = 1 AND CustomerI...

Runtime optimization of static languages: JIT for C++?

Is anyone using JIT tricks to improve the runtime performance of statically compiled languages such as C++? It seems like hotspot analysis and branch prediction based on observations made during runtime could improve the performance of any code, but maybe there's some fundamental strategic reason why making such observations and impleme...

Is there a good book on web application performance tuning?

I would like to read how to use caching effectively, optimize my database schema and queries, apply partitioning and load balancing. There are pretty much resources on optimizing code and low-level stuff but not the other. I've read Building Scalable Web Sites by Cal Henderson and besides a single chapter actually on scaling, which bar...

MySQL : selecting the X smallest values

Hi, Let be a table like this : CREATE TABLE `amoreAgentTST01` ( `moname` char(64) NOT NULL DEFAULT '', `updatetime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `data` longblob, PRIMARY KEY (`moname`,`updatetime`) I have a query to find the oldest records for each distinct 'moname', but only if t...

Will all methods in a logical expressions be executed?

In C#, given the two methods bool Action1(object Data); bool Action2(object Data); that are used in an if statement like this: if ( Action1(Data) || (Action2(Data) ) { PerformOtherAction(); } will Action2() still be called if Action1() returned true, or is this prevented by compiler optimisation, since it is already known tha...

Gems slowing down Rails test startup, can I selectively disable these?

I have a terrible Rails test startup time. When running a single functional test that may take 2 seconds to run, the total time from execution to returning to the command line could be up to 10-15 seconds. There are two gems I know are definitely getting in the way. A Facebook and Flickr gem (Facebooker, Flickraw). Facebooker will al...

MYSQL OR vs IN performance

I am wondering if there is any difference in regards to performance between the following SELECT ... FROM ... WHERE someFIELD IN(1,2,3,4) SELECT ... FROM ... WHERE someFIELD between 0 AND 5 SELECT ... FROM ... WHERE someFIELD = 1 OR someFIELD = 2 OR someFIELD = 3 ... or will MySQL optimize the SQL in the same way compilers will opt...

What is the most elegant way to do "foreach x except y" in PHP?

I want to do something like this: foreach ($array as $key=>$value except when $key="id") { // whatever } ... without having to put an "if" clause inside the body of the loop. It is not guaranteed that "id" will the be the first or last element in the array, and I don't really want to unset or slice the array, because that will be expe...

Selecting date intervals, doing it fast, and always returning the latest entry with the result.

I have a database with a table, storing changes in account-balance across a couple of accounts, with three columns; float balance, #The account balance after the change Date date, #Date that balance change occurred int aid #Account that the balance change occurred on It contains a couple of entries for each day of the...

BigDecimal: Can the Java compiler optimize away multiplications by 1?

Does the Java compiler remove multiplications by 1, when talking about BigDecimal? I'm standing in something similar to this: BigDecimal bd = getBigDecimal();//get arbitrary bigDecimal, could be anyone. bd = bd.multiply(new BigDecimal(getOneTwoOrThree()); Where the getOneTwoOrThree method is declared as: /* * Always returns Integ...

How can I optimize this Python code?

Profiling shows this is the slowest segment of my code for a little word game I wrote: def distance(word1, word2): difference = 0 for i in range(len(word1)): if word1[i] != word2[i]: difference += 1 return difference def getchildren(word, wordlist): return [ w for w in wordlist if distance(word, w) =...

An array stack algorithm without copy

I have a flashlite3 application with navigation consisting of icons the user can browse left or right through infinitely. The basic algorithm i'm using now works (and is adequate for this project) however, part of the solution depends on a duplicate of the array of icons. Depending on the number of items in the array, and/or the size of...

Algorithm for determining a file’s identity (Optimisation)

Further to this question: Algorithm for determining a file’s identity Recap: I'm looking for a cheap algorithm for determining a files identity which works the vast majority of the time. I went ahead and implemented an algorithm that gives me a "pretty unique" hash per file. The way my algorithm works is: For files smaller than a c...

Optimizing a PHP page: MySQL bottleneck

I have a page that is taking 37 seconds to load. While it is loading it pegs MySQL's CPU usage through the roof. I did not write the code for this page and it is rather convoluted so the reason for the bottleneck is not readily apparent to me. I profiled it (using kcachegrind) and find that the bulk of the time on the page is spent doin...

Complex SQL where clause: whether to factor logic

I've got a complex SQL where clause that just got more complex because of a requirements change. There are four basic sets of cases, each with a different combination of other factors. It's more readable (in my opinion) to have the four cases as separate branches of the where clause, and to repeat the redundant criteria in each branch. B...

How can I display the execution plan for a stored procedure?

I am able to view the Estimated Execution Plan (Management Studio 9.0) for a query without a problem but when it comes to stored procedures I do not see an easy way to do this without copying the code from the ALTER screen and pasting it into a query window, otherwise it will show the plan for the ALTER and not the procedure. Even after ...

Detecting load of <link> resources?

Browsers provide load events for <script> and <img> tags. Is there a way to detect whether a request to a element has completed? Specifically, I'm wishing to detect when a <link>'d stylesheet has been loaded. Unfortunately, I think using a sentinel style and detecting load from a computedStyle isn't workable in my situation. ...