optimization

How to optimize the picker view in iPhone?

I want my picker view can display 1 - 200. but I think it is too much memory, if I assign an Array in this view: self.myLargeView = [[NSArray alloc] initWithObjects:@"1 unit", @"2 units", .... ..., @"199 units" @"200 units", nil]; //code skipped How can I reduce the memory load in application? any ideas? ...

Why should or shouldn't I store a Dataset, Datatable, etc as a session variable in an ASP.NET page?

I am working on a web application that is consuming a Dataset returned by a web service. As the application is running I store that Dataset as a session variable to be used over and over again as the user navigates to the different pages that will edit the tables within the dataset. The idea was the user will only have to wait for t...

SQL: Quickly getting the value of column B wherever column A is minimum

I'm trying to do what seems like it should be a simple SQL operation, but I'm just not finding the right syntax to do it quickly. I'm using SQLite. The basic problem is that I have a table whose primary key is (objUid, time). It contains the columns objUid, time, and frame. For the purposes of this question, frame is an opaque value....

faster implementation of sum ( for Codility test )

How can the following simple implementation of sum be faster? private long sum( int [] a, int begin, int end ) { if( a == null ) { return 0; } long r = 0; for( int i = begin ; i < end ; i++ ) { r+= a[i]; } return r; } EDIT Background is in order. Reading latest entry on coding horror, I cam...

Consistant behaviour of float code with GCC

Hello, I do some numerical computing, and I have often had problems with floating points computations when using GCC. For my current purpose, I don't care too much about the real precision of the results, but I want this firm property: no matter WHERE the SAME code is in my program, when it is run on the SAME inputs, I want it to give ...

Optimizing for Internet Explorer

Hi, Being a web developer I have noticed that anything I create works absolutely great in all browsers, but always always always has a speed issue in Internet Explorer. Please note I am referring to speed, as I always take care that it displays and works across all browsers. Is there anywhere, or does anyone have, good programming tip...

Efficient recursion in functional programming vs. inefficient recursion in different paradigms

As far as I know recursion is very elegant but unefficient in OOP and procedural programming (see the wonderful "High Order perl", Mark Jason Dominus). I had some informations that in functional programming recursion is fast - keeping its elegance and simplicity. Could someone confirm and possibly amplify this? I am thinking in terms of...

Implementation of achievement systems in modern, complex games

Many games that are created these days come with their own achievement system that rewards players/users for accomplishing certain tasks. The badges system here on stackoverflow is exactly the same. There are some problems though for which I couldn't figure out good solutions. Achievement systems have to watch out for certain events al...

C# XNA: Optimizing Collision Detection?

I'm working on a simple demo for collision detection, which contains only a bunch of objects bouncing around in the window. (The goal is to see how many objects the game can handle at once without dropping frames.) There is gravity, so the objects are either moving or else colliding with a wall. The naive solution was O(n^2): foreach...

Optimizing MySQL query with several JOINs

I'm upgrading a script to a new version with a hole new database layout. The upgrade starts fine but slowly starts taking more and more time for the same query. The query in question is the following: SELECT nuser.user_id, nfriend.user_id AS friend_user_id, f.time FROM oldtable_friends AS f JOIN oldtable_user AS u ON ( u.user = f.user )...

Given a number, which interval does it fit in?

I have a 2 sets of intervals, like: xCoords: (0, 60], (60, 120], (120, 180] ... yCoords: (0, 60], (60, 120], (120, 180] ... The size of each interval is guaranteed to be the same, but the size of an xCoord interval doesn't have to be the size of a yCoord interval. (I could make that sacrifice in generality if necessary for optimizatio...

.NET Pooling IAsyncResult Objects

Hi, Reading through the SendAsync, BeginAsync method illustrations of Sockets, I realized that it was suggested to pool SocketAsyncEventArgs instances saying that it is a better than BeginXX, EndXX async approach since each call creates an IAsyncResult instance. I thought it was not that a great practice to pool objects that can be ins...

How to optimize this js (now CPU is over 40% when the page is opened)

I have this piece of JavaScript on my page and it loads the CPU considerably. Is there any way to optimize the code? ( I'm using jQuery, so jQuery solutions will be fine ) function Particle() { this.particleContainerWidth = $('#particle-container').width() - 100; this.particleContainerHeight = $('#particle-conta...

LINQ to Objects Optimization Techniques?

What LINQ to Objects optimization techniques do you use or have you seen in the wild? While waiting for "yield foreach" and other language/compiler optimizations to arrive in C# in 201x, I'm interesting in doing everything possible to make using LINQ everywhere less of a performance pain. One pattern I've seen so far is creating custom...

When, if ever, is loop unrolling still useful?

I've been trying to optimize some extremely performance-critical code (a quick sort algorithm that's being called millions and millions of times inside a monte carlo simulation) by loop unrolling. Here's the inner loop I'm trying to speed up: // Search for elements to swap. while(myArray[++index1] < pivot) {} while(pivot < myArray[--in...

mysql query normal relationship table vs concatenated realtionship table

I have a question about relationships between two tables. Let's say we have a table users, and links. users +++++++++ id name 1 name1 2 name2 3 name3 +++++++++ links +++++++++ id link 1 link1 2 link1 3 link1 +++++++++ Now the normal way to link these two is with a name_links table. For example: name_links ++++++++++++ uid ...

Which Data Structure? LinkedList or Any Other in Java?

I have specific requirements for the data structure to be used in my program in Java. It (Data Structure) should be able to hold large amounts of data (not fixed), my main operations would be to add at the end, and delete/read from the beginning (LinkedLists look good soo far). But occasionally, I need to delete from the middle also and ...

Interleaving updates to a .net dictionary inside a tight loop

Hi All, I'm working on an application that does processing at what I'd call fairly high throughput (current peaks in the range of 400 Mbps, design goal of eventual 10 Gbps). I run multiple instances of a loop which basically just cycles through reading and processing information, and uses a dictionary for holding state. However, i als...

Avoiding Calls to floor()

I am working on a piece of code where I need to deal with uvs (2D texture coordinates) that are not necessarily in the 0 to 1 range. As an example, sometimes I will get a uv with a u component that is 1.2. In order to handle this I am implementing a wrapping which causes tiling by doing the following: u -= floor(u) v -= floor(v) Doing...

Mysql Query optimisation

Query 1: SELECT cid, dl FROM chal WHERE cid IN ( SELECT cid FROM c_users WHERE uid = 636587 ); Query 2: SELECT chal.cid AS cid, chal.dl AS dl FROM chal, c_users WHERE uid = 808 AND chal.cid = c_users.cid; cid is primary key in chal cid and uid are...