• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: minimum function? (Modified by Simon Forster)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: minimum function? (Modified by Simon Forster)


  • Subject: Re: minimum function? (Modified by Simon Forster)
  • From: Axel Luttgens <email@hidden>
  • Date: Thu, 07 Apr 2005 00:35:02 +0200

has wrote:
Axel Luttgens wrote:

  
Why do you create a script object to hold the list of numbers? Why don't you access the list of number passed into the function directly? If it's a speed thing, can you explain a but further?

Speed! Just a matter of speed...
    

Efficiency, to be precise. Not quite the same thing.
  

With regards to Simon's original question, "efficiency" is a rather daring terminology.
For now on, one may only notice additional and rather illogical coding introduced in order to obtain higher execution speeds; the rationality acompanying the concept of efficiency is quite elusive in this very precise case.
Really, just speaking about "speed tricks" seems to be more appropriate (honest?) here.


  
Now, unless I'm wrong, a true explanation for this has never been provided.
    

Chris Nebel has explained the problem in the past, but I'm not going to hunt through the archives for a link to it.
I remember those threads very well; for those who might be interested, I have reproduced two excerpts hereafter.
 Short version, IIRC:

AppleScript's list objects are implemented as vector lists, which have a constant-time lookup when getting and setting items. It then adds additional error-checking code to this lookup operation that involves scanning every other item in the list, making lookups linear-time; the longer the list. (Note that this is plain brain-deadedness in the AppleScript implementation: other languages manage to implement robust vector lists without compromising efficiency.)

By some unspecified mechanism, this additional checking mechanism is bypassed when using certain reference forms, giving you constant-time lookups again (plus crashes if you're not careful how you do it). There's an obscure mention of this trick in the ASLG, and Emmanuel Levy's [IIRC] script object kludge is the best - or rather, least nasty - way to do it.
  

Isn't it exactly what I said?
We don't have a true explanation.
Just a quasi-information: it seems that some internal checks are not performed under certain circumstances.

Axel

=============

Michael Sullivan wrote on March 8th, 2002:
I wanted to post a copy of this over here because I'm not sure if any of
the apple folks read the macscrpt list.

In a discussion of sorts, and just how much faster Serge's qsort is than
a number of other folk's attempts at an n log n sort -- it came up that
applescript has a radically different time profile for accessing lists
through a reference (or encoded in a script object).  The standard
handling is *far* slower on long lists.

Here is Serge Belleudy-d'Espinose's sample for seeing the behavior in
question:


------ test script
set vList to {}
set vRange to 1000
repeat with i from 1 to vRange
    set end of vList to i
end repeat

set tStart to the ticks
-- slow
repeat with vItem in vList
    set vItem to contents of vItem
    -- do stuff with vItem
end repeat
set tMiddle to the ticks
-- fast
script vObject
    property xList : missing value
end script
tell vObject
    set its xList to vList
    repeat with vItem in its vList
        set vItem to contents of vItem
        -- do stuff with vItem
    end repeat
end tell
set tStop to the ticks
{tMiddle - tStart, tStop - tMiddle}
------ end test script

Note by trying different size lists that the behavior of the first
traversal is O(n^2), while the second one is O(n).

[...]
Should this be submitted as a bug report?

  


Christopher Nebel wrote on March 8th, 2002:
On Friday, March 8, 2002, at 08:17  AM, Michael Sullivan wrote:

[...]

It already has been. [...]  AppleScript takes a number of precautions to protect itself against circular structures, and one of them leads to this slow-down.  I'm not convinced that it really needs to do this, but changing it is not something to take lightly.



 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Re: minimum function? (Modified by Simon Forster) (From: has <email@hidden>)

  • Prev by Date: Re: minimum function?
  • Next by Date: Re: minimum function?
  • Previous by thread: Re: minimum function? (Modified by Simon Forster)
  • Next by thread: Re: minimum function? (Modified by Simon Forster)
  • Index(es):
    • Date
    • Thread