Optimizing an SBCL Application Program for Speed [closed] - common-lisp

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I've just finished and tested the core of a common lisp application and want to optimize it for speed now. It works with SBCL and makes use of CLOS.
Could someone outline the way to optimize my code for speed?
Where will I have to start? Will I just have to provide some global declaration or will I have to blow up my code with type information for each binding? Is there a way to find out which parts of my code could be compiled better with further type information?
The programm makes heavy use of a single 1-dimensional array 0..119 where it shifts CLOS-Instances around.
Thank you you Advance!

It's not great to optimize in a vacuum, because there's no limit to the ugliness you can introduce to make things some fraction of a percent faster.
If it's not fast enough, it's helpful to define what success means so you know when to stop.
With that in mind, a good first pass is to run your project under the profiler (sb-sprof) to get an idea of where the time is spent. If it's in generic arithmetic, it can help to judiciously use modular arithmetic in inner loops. If it's in CLOS stuff, it might possibly help to switch to structures for key bits of data. Whatever's the most wasteful will direct where to spend your effort in optimization.
I think it could be helpful if, after profiling, you post a followup question along the lines of "A lot of my program's time is spent in <foo>, how do I make it faster?"

Related

Effective simulation of large scale Modelica models by automatic translation to Modia [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
this is more of an hypothetical question, but might have great consequences. Lot of us in Modelica community are dealing with large scale systems with expensive simulation times. This is usually not an obstacle for bugfixing and development, but speeding up the simulation might allow for better and faster optimizations.
Recently I came across Modia possibilities, claiming to have superb numerical solvers, achieving better simulation times than Dymola, a state-of-the-art Modelica compiler. The syntax seemed to cover all important bits. Recreating large scale component models in Modia is unfeasible, but what about automatically translating the flattenized Modelica to Modia? Is that realistic? Would that provide a speed up? Has anyone tried before? I have searched for some
This might also hopefully improve integration of Modelica models and postprocesssing / identificaiton tooling within one language, instead of using FMI or invoking a separate executable.
Thanks for any suggestions.
For those interested, we might as well start developing this.
We in the Modia team agrees that the modeling know how in Modelica libraries must be reused. So we are working on a translator (brief details given in https://ep.liu.se/ecp/157/060/ecp19157060.pdf) from Modelica to Modia. The plan is to initially provide translated versions of Modelica.Blocks, Modelica.Electrical.Analog and Modelica.Mechanics together with Modia.

Last breaking changes to Ada [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
(Edited to narrow the question to Ada. Have posted other questions for Fortran and COBOL.)
I've spent some time in the past year dealing with changes to my code due to Python v2->v3 and R v3->v4 changes. It got me curious as to some of the older languages that are still in use.
I know Ada still sees occasional updates and functionality upgrades. I would assume that their mission-critical nature makes those changes smaller and more backward-compatible, but I don't really know and couldn't find it with a web search.
What and when were the last changes to Ada that was on the same rough order as the Python 2->3 changes?
Ada pays a lot of attention to reverse compatibility, to avoid breaking existing code, when making changes.
Last formal Ada release was Ada-2012, there is another one (Ada-202X) in progress.
Ada-2012 has a lot that Ada-83 doesn't, but I'd be surprised if there was anything more than trivial work to build an Ada-83 project (or Ada-95 or Ada-2005) in Ada-2012.
There are some differences though : from Ada-83 to Ada-2012 As you can see, there's really not much to say for 30 years of development.

Is recursion a Bad Practice in general? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
I always thought things that make your code uneasy to follow while being avoidable are considered as Bad Practice. Recursion seems to be one of these things (not to mention the problems it can cause like stack overflowing etc.), so I was a bit surprised when we had to learn working seriously with them during a programming course (for it ocassionally results in shorter code). And it seems to me there is a disagreement about it between the professors too...
People already asked this specific to languages (like Python, where a comment compared it to a goto statement), mostly specific to a problem, but I am interested in general:
Is recursion considered as a Bad Practice or not in the modern programming? When should I avoid it, and are there any circumstances when can't?
Related questions I found:
Is recursion a feature in and of itself? (does not discuss whether it is good or bad)
Is recursion ever faster than looping? (answer describes that recursion can result in improvements in functional languages, but is expensive in others), also other questions discussing the performance
Recursive programming is not a bad practice. It is a tool in your toolbox and like any tool, when it's the only tool used that's when bad things happen. Or when it's used out of a proper context.
When do you use recursion? It's good when you have a tree dataset that you need to perform the same logic upon. For example: You have a tree list of string elements and you wish to calculate total length of all strings, down one branch. You'd define a method to calculate the length of a list element and then see if the element has a sibling and if it does call the method, passing the sibling - and the process starts over.
The most common pitfall would be of a stack overflow. When the list is so large, it can't be handled all at once. So you would implement checks to ensure this never happens. Such as breaking the linked list down into manageable pieces and in your function, utilize a static variable to track the number of levels you traverse - bailing once that number is exceeded.
You should avoid using when your dataset is not a tree type dataset. The only time I can think of that you actually can't avoid using recursion is in programming languages that do not support looping (Haskell).

Recursion When to use it? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
So we just finished the subject recursion in school and I am still wondering "why?".
I feel like I have just learned a hell of a lot about math in a programming way with the sole purpose of passing an exam later on and then never again.
So what I want to know is when to use it? I can only find people saying "when you want to call a function within itself" but why would you do that?
Recursion is the foundation of computation, every possible program can be expressed as a recursive function (in the lambda calculus). Hence, understanding recursion gives you a deeper understanding of the principles of computation.
Second, recursion is also a tool for understanding on the meta level: Lots of proofs over the natural numbers follow a pattern called "natural induction", which is a special case of structural induction which in turn allows you to understand properties of very complex systems in a relatively simple way.
Finally, it also helps to write good (i.e. readable) algorithms: Whenever there is data to store/handle in a repetitive calculation (i.e. more than incrementing a counter), you can use a recursive function to implicitly manage a stack for you. This is also often very efficient since most systems come with a machine stack at hand.

Unix Parent-child process relationship [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
i understand well the parent-child relationship in unix processes creation. But i don't understand the rationale behind it :( why do we need to fork from the current process to create a new one, then overwrite its image with a new code if any? cheers
The rationale is that unix system calls (at least originally) are "elementary" operations done by the kernel.
In practice, applications often do some specific things between fork(2) and execve(2), in particular calls to close(2) and dup2(2), also sigaction(2) to ignore some signals (with perhaps some pipe(2) syscalls done before the fork).
If you wanted to have a single syscall handling all this at a time, it would have been very complex, and less flexible.
I suggest to read some book like Advanced Linux Programming (it is free and online) or Advanced Unix Programming in addition of intro(2).
I find on the contrary the intent to separate creating a process and executing a program quite natural. I don't really understand why you want both operations to be combined.
See also this mine answer about syscalls.

Resources