• 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: 'my' problem is your problem: it chokes without 'my'! BUG
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: 'my' problem is your problem: it chokes without 'my'! BUG


  • Subject: Re: 'my' problem is your problem: it chokes without 'my'! BUG
  • From: Harald E Brandt <email@hidden>
  • Date: Wed, 26 Jan 2011 19:51:15 +0100


On 25 jan 2011, at 22.21, Nigel Garvey wrote:

It's a fairly well understood AppleScript list phenomenon. Putting 'my' in front of a list variable name produces a reference to that variable. It's the same reference produced by 'set theDataRef to a reference to theData', only it's compiled into the code rather than being stored in a variable. Using this in references to the list's items and properties greatly speeds up access to those items and properties.

Thanks Nigel for the explanation; it was pretty obscure to me.
I wasn't aware of that 'my' had that effect, only it's effect in tell blocks and script objects, and for ASObjC properties.

I did some further speed tests: But using 'my' or 'a reference to' will only work if the variable is a property or a global, i.e it won't work for a local variable in a handler. This can be solved, however, by creating a temporary (local) script object inside the handler, which makes it possible to set a (local) property in the script object, thereby making it possible to use 'my' for all cases of appending to a list. Tests reveal that already with a 100-element list there is a significant gain, for 1000 elements the gain is huge, for 10000 elements it won't work without 'my'. There is virtually no extra cost associated with this "embedded" script object, so it is usable even for a 10-element list, although there is no gain to be had for such small lists compared with a solution that does not use 'my' or 'a reference to'.

After the original measurement it occurred to me that I did run the computer without battery, which strangely makes it slow down a lot. With battery installed, it ran the script in about 6.6 seconds rather than 12.5 seconds I first mentioned.

(The reason I sometimes run it without battery when using external monitor is to save the battery somewhat (reduced aging/damaging) and it makes the fan run slow, making it quiet.)

--heb
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

References: 
 >Re: 'my' problem is your problem: it chokes without 'my'! BUG (From: "Nigel Garvey" <email@hidden>)

  • Prev by Date: Re: passing handler problems and a resolution
  • Next by Date: Re: passing handler problems and a resolution
  • Previous by thread: Re: 'my' problem is your problem: it chokes without 'my'! BUG
  • Next by thread: event log history window
  • Index(es):
    • Date
    • Thread