2

for simplicity, say we have an array of personal contacts, the first key is the contact name, and there are subkeys which include phone number, address, email, notes and date of birth

how many contacts could be held in an array in memory without running into performance issues?

for reference, this would be running on older machines with 512MB of RAM running Debian Linux, so resources are scarce

MadPink
  • 294
  • 1
  • 10
  • Runtime performance will remain very good. In my stress testing I've loaded a couple hundred MBs into arrays with no noticeable delay - the team uses a good hash. The bigger issue will be loading the array initially from disk - how do you populate it? – FourthWorld Jul 18 '15 at 23:49
  • I'm not concerned as much about the loading for this application; there will be a local storage that syncs with a CouchDB server, and I expect the process to take a little bit to start up; my big concern is how it handles resources over the course of several hours of running, and I am quite comfortable so far with what I have found – MadPink Jul 19 '15 at 11:15

2 Answers2

2

I'd be interested in knowing the answer to this as well..I was however going to do some testing myself on my app ..... its really easy to populate an array automatically.

global MyTestArray

repeat with x = 1 to 1000000
put uuid("random") into MyTestArray[x]["key1"]
put uuid("random") into MyTestArray[x]["key2"]
end repeat

to time your handlers use:

on TimedHandler

local start_time

put the milliseconds into start_time

// your handler that reads the array

put the milliseconds into end_time
answer (the milliseconds - start_time) / 1000

end TimedHandler
  • well I gave this stress test a shot and had pretty good results on my laptop, I started at 100000 records and kept adding another 100k and testing differences, ultimately there was no difference in time as I approached a million records; will try this on one of the older machines this week – MadPink Jul 19 '15 at 10:49
1

You won't find much slow-down as arrays increase. In an ideal situation, an array doesn't slow down because the amount of data increases; it only slows down by adding millions of keys.

In other words, if your array has a few gigabytes of data and your computer is a 64 bit machine with sufficient memory, your computer simply won't slow down at all. If you have a 32 bit machine and you're loading more than 4 GB data, it will make heavy use of virtual memory and you will see significant slow down.

As your array has more keys, the search routine that finds the right key may need a little more time, but as long as you have less than a few billions contacts in your database (I would assume 2^32 contacts but I didn't check the exact number) I would expect any slow-down to be of an acceptable magnitude.

However, since you indicate to be using older machines with 512MB ram, the size of the data is likely to become a problem. The biggest problem will be that eventually you may have a data stack bigger than the size of available memory. Debian will take about half of the physical memory, which means that you have the other half of 256MB available for other apps, including your contacts database. If your app uses a nice GUI, your app will quickly need more than 256MB of memory and it is going to rely heavily on virtual memory, causing it to slow down.

Additionally, arrays aren't always the best solution. First of all, you are probably better off using SQLite. SQLite has very fast specialized search routines, which are fast than any LiveCode routine using arrays. Second, a repeat for each line loop using a simple list is sometimes faster than a repeat for each key loop, because for each lineaccess the data directly while repeat for each key first loops through the keys and then still needs to access the array to check what is in the element of that key.

Mark
  • 2,380
  • 11
  • 29
  • 49
  • thanks! the main reason I am straying away from SQLite is that the data itself is rather unstructured and can't be easily put into a table, coming in the form of JSON documents from CouchDB; but I might give the simple list idea a try – MadPink Jul 20 '15 at 10:55