optimization

Mysql: Optimizing Selecting rows from multiple ranges (using indexes?)

My table (projects): id, lft, rgt 1, 1, 6 2, 2, 3 3, 4, 5 4, 7, 10 5, 8, 9 6, 11, 12 7, 13, 14 As you may have noticed, this is hierarchical data using the nested set model http://tr.im/EO3G. Tree pretty-printed: 1 2 3 4 5 6 7 I want to select all sub projects under project 1 and 4. I can do this with: SELECT p.id FROM projects...

Most optimized way to store crawler states ?

Hi there, I'm currently writing a web crawler (using the python framework scrapy). Recently I had to implement a pause/resume system. The solution I implemented is of the simplest kind and, basically, stores links when they get scheduled, and marks them as 'processed' once they actually are. Thus, I'm able to fetch those links (obviousl...

SQL Table Size And Query Performance

We have a number of items coming in from a web service; each item containing an unknown number of properties. We are storing them in a database with the following Schema. Items - ItemID - ItemName Properties - PropertyID - PropertyName - PropertyValue - PropertyValueType - TransmitTime - ItemID [fk] The properties tabl...

PHP file writing optimization

EDIT: Optimization results at end of this question! hi, i have a following code to first scan files in a specific folder and then read every file line by line and after numerous "if...else if" write new modified file to another folder with the name name as it was when opened. The problem is that writing a file line by line seems to be ...

Optimizing a LAN server for a game.

I'm the network programmer on a school game project. We want to have up to 16 players at once on a LAN. I am using the Server-Client model and am creating a new thread per client that joins. However, a lot of CPU time is wasted just checking on each thread if the non-blocking port has received anything from the client. I've been read...

I just wrote a horrible PHP function, I need some help (elseif chain - switch?)

Hi, I am making a site that determines the value of an array based on what time it is. I wrote this awful (functional) script, and am wondering if I could have made it more concise. I started with a case/switch statement, but had trouble getting multiple conditionals working with it. Here's the dirty deed: if ($now < november 18th) { ...

What's a good SWF optimizer?

What's a good SWF optimizer? ...

compiler optimization implementation

Actually I am making a major project in implementing compiler optimization techniques. I already know about the existing techniques, but I am confused what technique to choose and how to implement it. ...

SQL : Optimizing query to have few IO operations

How can i rewrite the below query to return results with few IO operation and less response time select *, (select Product_Name from InventoryMaster J2 where J1.ParentItem=J2.ItemId) as ParentName, (select Description from InventoryMaster J2 where J1.ParentItem=J2.ItemId) as ParentDesc from InventoryMaster J1 where Flag...

Java: Calculate SHA-256 hash of large file efficiently

I need to calculate a SHA-256 hash of large file (or portion of it). My implementation works fine, but its much slower than the C++'s CryptoPP calculation (25 Min. vs. 10 Min for ~30GB file). What I need is a similar execution time in C++ and Java, so the hashes are ready at almoust the same time. I also tryed the Bouncy Castle implement...

How do modern optimizing compilers determine when to optimize?

How do modern optimizing compilers determine when to apply certain optimizations such as loop unrolling and code inlining? Since both of these affect caching, naively inlining functions with less than X lines, or whatever other simple heuristic, is likely to generate worse performing code. So, how do modern compilers deal with this? I'...

Optimizing the creation of objects inside loops

Which of the following would be more optimal on a Java 6 HotSpot VM? final Map<Foo,Bar> map = new HashMap<Foo,Bar>(someNotSoLargeNumber); for (int i = 0; i < someLargeNumber; i++) { doSomethingWithMap(map); map.clear(); } or final int someNotSoLargeNumber = ...; for (int i = 0; i < someLargeNumber; i++) { final Map<Foo,Bar>...

Javascript stops working when compress script

I want to compress my 2000+ lines og javascript and I have tested both http://dean.edwards.name/packer/ and http://closure-compiler.appspot.com/home. But in both cases, the compressed script gives me errors. An example of a error is jQuery(document).Da is not a function. Why isn't my scripts working after optimazation? And what can I d...

gcc -fPIC seems to muck with optimization flags

Following along from this question: how-do-i-check-if-gcc-is-performing-tail-recursion-optimization, I noticed that using gcc with -fPIC seems to destroy this optimization. I am creating a shared library, but I doesn't seem to need the -fPIC option. Well, my question is, why does -fPIC change gcc optimizations ? Do I need to keep -fPIC ...

MySQL query need optimization

Hi all, I got this query: SELECT user_id FROM basic_info WHERE age BETWEEN 18 AND 22 AND gender = 0 ORDER BY rating LIMIT 50 The table looks like (and it contains about 700k rows): CREATE TABLE IF NOT EXISTS `basic_info` ( `user_id` mediumint(8) unsigned NOT NULL auto_increment, `gender` tinyint(1) unsigned NOT NULL d...

Is it a way to know whether Index was used for a particular sql query

Sometimes one when creating SQL queries one assumes that one of the Index should be used by the engine when getting the data. But not always. If some of the necessities are absent the engine will probably process the rows one by one. Is it a way (for sqlite) to know for sure that the index was used? I mean in cases more complex than SELE...

Optimize PHP, MYSQL community website performance

Hi, I own a community website of about 12.000 users (write heavy), 100 concurrent users max on a single VPS with 1Gb ram. The load rarely goes above 3 and response is quite good. Currently a simple file cache is used to store DB query results to ease the load on the DB, but the website still can slow down over 220 concurrent users (loa...

Solving for optimal alignment of 3d polygonal mesh

I'm trying to implement a geometry templating engine. One of the parts is taking a prototypical polygonal mesh and aligning an instantiation with some points in the larger object. So, the problem is this: given 3d point positions for some (perhaps all) of the verts in a polygonal mesh, find a scaled rotation that minimizes the differen...

What is optimal method for accessing function parameters in javascript?

Of these similar function definitions, what is optimal way to access arguments and why? function DoStuff() { return arguments[0] + arguments[1] + arguments[2]; } function DoStuff(first, second, third) { return first + second + third; } Does one allocate less memory than the other? Is one faster to access the parameter values ...

Convenient way to use LIKE case sensivity in sqlite

As I see LIKE operator can optimize query if I switch PRAGMA case_sensitive_like=ON. I measured, it really worked, queries "LIKE someth%" becomes ten times faster on a compartively large binary indexed tables. But the problem is that my library implemented as an add-on to my application, it maintains its own tables with any db it is conn...