Post Reply 
compiled or not?
12-15-2015, 12:41 AM (This post was last modified: 12-15-2015 12:43 AM by ji3m.)
Post: #1
compiled or not?
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.

I work with android Prime only for now on my
Galaxy Tab Pro/Note 2
Find all posts by this user
Quote this message in a reply
12-15-2015, 02:26 AM
Post: #2
RE: compiled or not?
(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.

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.

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?

-Luis-
Find all posts by this user
Quote this message in a reply
12-15-2015, 04:03 AM
Post: #3
RE: compiled or not?
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.




My website: ried.cl
Visit this user's website Find all posts by this user
Quote this message in a reply
12-15-2015, 05:56 AM
Post: #4
RE: compiled or not?
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

Although I work for the HP calculator group, the views and opinions I post here are my own. I do not speak for HP.
Find all posts by this user
Quote this message in a reply
12-15-2015, 07:02 AM
Post: #5
RE: compiled or not?
(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.
Find all posts by this user
Quote this message in a reply
12-15-2015, 01:50 PM (This post was last modified: 12-15-2015 01:51 PM by ji3m.)
Post: #6
RE: compiled or not?
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.

I work with android Prime only for now on my
Galaxy Tab Pro/Note 2
Find all posts by this user
Quote this message in a reply
12-16-2015, 06:35 AM
Post: #7
RE: compiled or not?
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

Although I work for the HP calculator group, the views and opinions I post here are my own. I do not speak for HP.
Find all posts by this user
Quote this message in a reply
12-16-2015, 01:04 PM
Post: #8
RE: compiled or not?
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.

I work with android Prime only for now on my
Galaxy Tab Pro/Note 2
Find all posts by this user
Quote this message in a reply
12-17-2015, 03:39 PM
Post: #9
RE: compiled or not?
(12-15-2015 07:02 AM)hpfx Wrote:  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.

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)
BEGIN
 RETURN 2*x;
END;

EXPORT aaa(x)
BEGIN
 RETURN dbl(x);
END;

I think the only time you really NEED forward declarations is when you have two functions that are mutually recursive.

Code:
// forward declaration required
m(n);

f(n)
BEGIN
 RETURN IFTE(n==0, 1, n-m(f(n-1)) );
END;

m(n)
BEGIN
 RETURN IFTE(n==0, 0, n-f(m(n-1)) );
END;

EXPORT HFM(n)
BEGIN
 PRINT;
 PRINT(f(n));
 PRINT(m(n));
END;
Find all posts by this user
Quote this message in a reply
12-17-2015, 09:58 PM (This post was last modified: 12-17-2015 10:01 PM by hpfx.)
Post: #10
RE: compiled or not?
(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...
Find all posts by this user
Quote this message in a reply
12-18-2015, 01:12 PM
Post: #11
RE: compiled or not?
(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. :-)
Find all posts by this user
Quote this message in a reply
12-18-2015, 05:15 PM
Post: #12
RE: compiled or not?
(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 Wink
Find all posts by this user
Quote this message in a reply
12-18-2015, 07:27 PM (This post was last modified: 12-18-2015 07:28 PM by ji3m.)
Post: #13
RE: compiled or not?
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 .

I work with android Prime only for now on my
Galaxy Tab Pro/Note 2
Find all posts by this user
Quote this message in a reply
12-19-2015, 12:00 AM (This post was last modified: 12-19-2015 12:03 AM by eried.)
Post: #14
RE: compiled or not?
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.

[Image: YfJrlYGl1yrqoe2UCx8P8GLHFbVQSZCrDcuXKSVn...gHqGSbjI6g]

My website: ried.cl
Visit this user's website Find all posts by this user
Quote this message in a reply
12-19-2015, 05:08 AM
Post: #15
RE: compiled or not?
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.

I work with android Prime only for now on my
Galaxy Tab Pro/Note 2
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 3 Guest(s)