compiled or not? - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html) +--- Forum: HP Prime (/forum-5.html) +--- Thread: compiled or not? (/thread-5337.html) |
compiled or not? - ji3m - 12-15-2015 12:41 AM I had presumed that ppl was "compiled" in the sense that all variables and function names were resolved at compile time. But this really can't be true since there is no linker step. As my program got larger it also ran slower and slower. It seems that all variables and functions are looked up (resolved) by runtime searches through all the various scopes. So my questions is, are the runtime symbol tables sorted.? If so is it alphabetical? Should my most used variables be aaaamyvar or AAAAmyvar if performance is important. I am measuring almost 1 millisecond per variable access but it varies widely with the number of variables. RE: compiled or not? - luisphysics - 12-15-2015 02:26 AM (12-15-2015 12:41 AM)ji3m Wrote: I had presumed that ppl was "compiled" in the sense that all variables and function names were resolved at compile time. But this really can't be true since there is no linker step. My question would be how large and complex is your program. You need to ask yourself. Are you using the right tool for the job? RE: compiled or not? - eried - 12-15-2015 04:03 AM From what I observed in the emulator, the code is "compiled" to an intermediate code. It is not really compiled to machine code, but to some kind of bytecode. RE: compiled or not? - cyrille de brébisson - 12-15-2015 05:56 AM Hello, PPL text is transformed into an evaluation tree which represents the original code but is much faster to execute/access. Variables are kept as text and looked up when needed. One of the reason for this is that, since PPL is, at least partially a symbolic language (you can create an equation and pass it around, with QUOTE for example), what might look like a local (for example), might actually be a global when executed. Also, PPL has WAY more type of variables that C or C++, and has the ability to modify its own variables (to some extend). (variables types are: home build in, home user, app build in, app users, app exported program, exported program, current program global, local, CAS)... At this point, variables are not sorted. This is, to some extend, under the assumption that each program block is 'small'. ie, that each list of variable is small. Local variable, for example, one 'list' of local variable gets created when a user function is called, and each time the LOCAL keyword is used. Since LOCAL can only create 8 variables at the same time, this limits the use of a sort search. It is true that I could at least sort the symbols in programs. It would indeed help for program global variables and program function search. Quite frankly, I never dreamed that people would create program that large and complex with this little language and therefore never thought of such issues! Cyrille RE: compiled or not? - hpfx - 12-15-2015 07:02 AM (12-15-2015 05:56 AM)cyrille de brébisson Wrote: It is true that I could at least sort the symbols in programs. It would indeed help for program global variables and program function search. While you are there, can we get rid of that forward declaration of functions ? You could collect symbol at compilation and avoid requesting user to list functions at begining of program. It makes years new language does not require it anymore. I had to explain that to my son, it's not obvious for youngers, does not add anything and make programs more complex. RE: compiled or not? - ji3m - 12-15-2015 01:50 PM The app is about 7300 lines of code. Currently about 80 variables are exported for debugging. The program neednt export anything if that woukd help performance. Ppl is the only tool since the program is an rpl interpreter for the prime itself. I assumed ppl would compile to bytecodes or similar. But notwithstanding the polymorphic nature of variables, i assumed they would be compiled to an index into a global symbol table. But that would require a linking phase for all programs. The most used variables are STK (the rpn stack list ) and SP (the rpn stack pointer). These take about a millisec to access. If i move STK and SP from the main app program to a tiny pgm access time is cut in half. So it appears that the global table is searched first. Yes PPL is a simple but pretty powerful language. The list handling is superior and i wouldn't attempted the project if wasn't so. RE: compiled or not? - cyrille de brébisson - 12-16-2015 06:35 AM Hello, Wether a variable in the current program is exported or not does not change anything to the lookup time. It will find the program associated with the current user executed function and then look for the variable or function in this program sequentially. Making sure that the variable name differ on the first letter will speed things up obviously (if you make all your variables 31 characters with only a difference on the last character, it will be somewhat slower). Forward declaration are needed because the compiler is 'single pass'. This means that the compiler reads the source only once. Not requiring forward forces 2 full passes, dividing the compilation speed by 2. I will put it on the long list of things to look at. Cyrille RE: compiled or not? - ji3m - 12-16-2015 01:04 PM I dont know the innards of the ppl implementation, but it seems to me that in the single pass an entry for all fumctions and variables within the single file exist in a symbol table. That table could have a link to the final address of code or data object at the end of the single pass. The index into that table saved in the code object should remove the need for a runtime search. Only true extermals would require name searches. Access time would then be constant within that (presumably large) file. Even now I measure acess times of less than 50 microseconds in a tiny program vs 1 or more millsecs in a large program. RE: compiled or not? - Wes Loewer - 12-17-2015 03:39 PM (12-15-2015 07:02 AM)hpfx Wrote: While you are there, can we get rid of that forward declaration of functions ? When I was first learning programming, one thing that made sense to me was the idea that you had to define a new word before you could use it. Instead of using forward declarations, the prof had us just define the function first: Code: dbl(x) I think the only time you really NEED forward declarations is when you have two functions that are mutually recursive. Code: // forward declaration required RE: compiled or not? - hpfx - 12-17-2015 09:58 PM (12-17-2015 03:39 PM)Wes Loewer Wrote: When I was first learning programming, one thing that made sense to me was the idea that you had to define a new word before you could use it. Instead of using forward declarations, the prof had us just define the function first: The prof found a nice story to explain why you should define these functions first. Ok, at that time it was expensive in term of ressource to have language that do not require that every symbols to be defined. In fact, it's a technology issue. Do you also define every builtin functions you are going to use in your program ? Of course no, because you are not obliged to and because you probably can't do, by the way. Nevertheless aren't builtins like "words" to be defined too ?... For me, I even don't make a difference between builtins and my functions : they are both available. When I build a program I (would) like to organize the order of my function not because of the technology, but because of logic, or to group functions by domain, or whatever else... For example I like to start with my entry point, where is major steps of the process that describe quite well the program... It's a pain to mentally build a kind of dependance graph to place definitions or to forward declare. I understand it worked like that on 30 year old languages, that's ok. Also, it's not a strong issue on hpprime while programs remain small. But if you want bigger program, it's maybe something to think about... RE: compiled or not? - Wes Loewer - 12-18-2015 01:12 PM (12-17-2015 09:58 PM)hpfx Wrote: I understand it worked like that on 30 year old languages, that's ok. Well, now that you mention it, it was just over 30 years ago that I sat in that programming class. :-) RE: compiled or not? - hpfx - 12-18-2015 05:15 PM (12-18-2015 01:12 PM)Wes Loewer Wrote: Well, now that you mention it, it was just over 30 years ago that I sat in that programming class. :-)I'm as old as you RE: compiled or not? - ji3m - 12-18-2015 07:27 PM 55 years for me. Fortran, ibm 1620 core machine. Prine is over one million times faster or more. But Off topic. It was about speeding up a large program . RE: compiled or not? - eried - 12-19-2015 12:00 AM I don't have so many years past my first programming class but the first time we used C, the teacher explained this concept... HOWEVER, after I understand that, I think waiting ~0.00001s waiting the compiler to do a second pass to declare these functions is quite acceptable. It seems to work perfectly in modern languages. Considering too how awkward it is to reorder code blocks in the Prime. RE: compiled or not? - ji3m - 12-19-2015 05:08 AM Forward function declarations are not a problem. I just wish it were also true for variables as well. But my main point is a second pass is not required to remove string lookups in a single prgram file. It just requires object to keep an index into the file local symbol table and an indirect call to the address of that symbol (code or variable) at runtime. The same is tru for local variables although not so important timewise. In my rpl implementation ( which is built on ppl) all references are through indices into lists. What i can't overcome, however, is the huge time spent by ppl in finding the target function or variable. Access time appears to be significantly larger than code execution. Most of my code is small routines ( the object prolog handlers ala rpl) so most of the time is gettig there. So performance drops from megahz to less than a khz. Pretty slow. |