Author Topic: Autolisp Optimization  (Read 1316 times)

0 Members and 1 Guest are viewing this topic.

SIDESHOWBOB

  • Guest
Autolisp Optimization
« on: December 21, 2012, 06:58:22 AM »
Has anyone written some general guidelines for optimization of autolisp?

I recently found that assoc on lists of around 200 items seems to perform twice as fast as member, and the factor is more impressive for lists of (or association lists keyed on) integers rather than strings.  Both still seem to be linear in the length of the list though.

If you do funny things like put functions within functions to encapsulate them, e.g.

Code - Auto/Visual Lisp: [Select]
  1. (defun foo ( / bar)
  2.  (defun bar ( /) nil)
  3.  (bar)
  4. )
  5.  

does that affect linking and hence the speed of runtime function calls?

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: Autolisp Optimization
« Reply #1 on: December 21, 2012, 10:16:25 AM »
Most of my optimization is for readability and useability.  For example, I sometimes nest (defun ...) calls where I would have multiple calls to a procedure but only in one function which gets called infrequently.  I can keep the name short and on point without having to worry about it being overridden by another local function, while avoiding unnecessarily copied code.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

SIDESHOWBOB

  • Guest
Re: Autolisp Optimization
« Reply #2 on: December 21, 2012, 10:25:58 AM »
Looking at compile output my code actually fails to link entirely across files - it's littered with warnings that functions were not linked!  Of course it still finds them at run time.

What can I do to make sure it finds them for optimization?

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: Autolisp Optimization
« Reply #3 on: December 21, 2012, 12:03:37 PM »
Given the capabilities of hardware required to run AutoCAD, I'm not sure you would see much, if any, benefit from the time expended tracking all that down.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}