Groups | Search | Server Info | Login | Register


Groups > comp.lang.forth > #22679

Re: The current object

From Bernd Paysan <bernd.paysan@gmx.de>
Newsgroups comp.lang.forth
Subject Re: The current object
Date 2013-05-16 17:45 +0200
Organization 1&1 Internet AG
Message-ID <kn2utv$afr$1@online.de> (permalink)
References (12 earlier) <klu9fd$ifv$1@online.de> <kn0aqb$d3v$1@online.de> <R5CdndY-5plDUg7MnZ2dnUVZ_hOdnZ2d@supernews.com> <kn0udd$spc$1@online.de> <KvydncG8nbdXFAnMnZ2dnUVZ_rydnZ2d@supernews.com>

Show all headers | View raw


Andrew Haley wrote:
>> Actually, the likelyhood that the object itself (and therefore the
>> class information) is not in the cache might be higher.
> 
> Well, yes.  But you've probably got to fetch the object anyway.

Yes, but cache misses are all about likelyhood.  If it's pretty likely that 
there is a cache hit on the vtable access, it's going to be fast.

>> There aren't that many vtables in a reasonable large Forth OOP
>> program.  Maybe in Java.
> 
> What is a "Forth OOP program"?  These claims of exceptionalism aren't
> working.

Forth OOP programs are usually written by single persons or small teams, 
just like any other Forth program.  Forth's solution to the "large team 
problem" is that you don't need the large team; the small team will do just 
fine.  This is our target audience.  We need to design for them, not for 
Google, IBM, SAP, or Oracle.  We also don't need to make the "my code/your 
code" party happy, which doesn't even like if someone else *looks* into 
their code.

>> No, you didn't read that correctly: If you have a mostly monomorphic
>> call, which has the occasional polymorphic call, it's going to be
>> slow if you convert from monomorphic to polymorphic on the first of
>> those ocassional calls, and never go back.
> 
> That's only true if the handling of a polymorphic call is particularly
> slow, and I don't think it is.

Neither do I, I think a polymorphic call is slightly faster than the inline 
caching.  The only reason to use inline caching is when the polymorphic call 
is somewhat slower.

> Point taken.  I'm thinking in more general terms than small programs
> that fit nicely in cache.

As Anton points out, caches work quite well for larger programs, too.

> And it maybe explains some of the other things you've said about the
> design of your system.  If the programs are that small -- small enough
> to fit in a single programmer's head -- the advantages gained from
> encapsulation and isolating classes from subclasses are reduced.  You
> really can look at every call and see if it needs to be polymorphic in
> this program.

Yes.  Forth's design philosophy is about understanding the whole program.  
Encapsulation and isolation is for development where the philosophy is that 
you should *not* understand the program.  This is the road to bloated crap.

>>> That's not what we do.  It's
>>> 
>>>    mov r1, #constant
>>>    call method
>>>    ...
>>>    mov r2, [obj]
>>>    cmp r2, r1
>>>    bne ...
>> 
>> Still two branches, still needs two cycles per invocation.  Even a
>> predicted fall-through branch costs one cycle.  The order here
>> doesn't really matter, it's just reducing the code size (more call
>> sites than methods - but then, you need to create that code again
>> for every subclass, even if that subclass doesn't change the method
>> at all).
> 
> Why do you need to create the code again for every subclass?  What is
> the code you're recreating?

I'm thinking of this "is this my class - if yes, perform the method, 
otherwise continue".  So if you subclass, you have to generate another "is 
this my class" test.  Or you need to put some "load superclass, and 
reiterate" thing.

>> I hope that the polymorphic dispatch jumps right after the
>> bne into the method, without double checking.
> 
> After a test succeeds, you execute code.

Ok, then there's at least something missing.  You have to update r1 at some 
point.  How many of these tests do you need for a polymorphic dispatch?  
Remember: *One* test is enough to make this slower than the vtable call.  If 
it's O(N) or O(log N) for N classes, there's no point to consider it.

I've seen arguments about vtable dispatching where people argue that if your 
method is defined in a super class, you have to look it up in the superclass 
vtable.  That's what I consider incompetence.  Of course, you "finalize" 
your vtables so that they already contain the superclass methods where 
necessary.

-- 
Bernd Paysan
"If you want it done right, you have to do it yourself"
http://bernd-paysan.de/

Back to comp.lang.forth | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Re: The current object (was: Went open source with my GA144 ...) Bernd Paysan <bernd.paysan@gmx.de> - 2013-05-02 19:58 +0200
  Re: The current object (was: Went open source with my GA144 ...) anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-05-03 16:50 +0000
    Re: The current object (was: Went open source with my GA144 ...) Bernd Paysan <bernd.paysan@gmx.de> - 2013-05-04 18:58 +0200
      Re: The current object Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-05-04 13:35 -0500
        Re: The current object Bernd Paysan <bernd.paysan@gmx.de> - 2013-05-05 01:08 +0200
          Re: The current object Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-05-04 18:29 -0500
            Re: The current object Bernd Paysan <bernd.paysan@gmx.de> - 2013-05-05 03:00 +0200
              Re: The current object Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-05-05 03:48 -0500
                Re: The current object Bernd Paysan <bernd.paysan@gmx.de> - 2013-05-05 23:15 +0200
                Re: The current object Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-05-06 05:01 -0500
                Re: The current object Bernd Paysan <bernd.paysan@gmx.de> - 2013-05-07 03:23 +0200
                Re: The current object Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-05-07 03:39 -0500
                Re: The current object Bernd Paysan <bernd.paysan@gmx.de> - 2013-05-07 19:00 +0200
                Re: The current object Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-05-07 13:34 -0500
                Re: The current object Bernd Paysan <bernd.paysan@gmx.de> - 2013-05-07 22:00 +0200
                Re: The current object anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-05-08 07:26 +0000
              Re: The current object Doug Hoffman <glidedog@gmail.com> - 2013-05-05 06:39 -0400
                Re: The current object Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-05-05 09:15 -0500
                Re: The current object Paul Rubin <no.email@nospam.invalid> - 2013-05-05 09:25 -0700
                Re: The current object Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-05-05 11:43 -0500
                Re: The current object Paul Rubin <no.email@nospam.invalid> - 2013-05-05 09:59 -0700
                Re: The current object Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-05-06 05:06 -0500
                Re: The current object Mark Wills <forthfreak@gmail.com> - 2013-05-06 00:19 -0700
              Re: The current object "WJ" <w_a_x_man@yahoo.com> - 2013-05-13 22:45 +0000
          Re: The current object Doug Hoffman <glidedog@gmail.com> - 2013-05-05 06:39 -0400
            Re: The current object Bernd Paysan <bernd.paysan@gmx.de> - 2013-05-05 23:40 +0200
      Re: The current object Doug Hoffman <glidedog@gmail.com> - 2013-05-05 06:39 -0400
        Re: The current object Bernd Paysan <bernd.paysan@gmx.de> - 2013-05-05 23:29 +0200
          Re: The current object Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-05-06 05:10 -0500
          Re: The current object Doug Hoffman <glidedog@gmail.com> - 2013-05-08 07:35 -0400
            Re: The current object Bernd Paysan <bernd.paysan@gmx.de> - 2013-05-09 00:06 +0200
              Re: The current object Doug Hoffman <glidedog@gmail.com> - 2013-05-09 06:41 -0400
                Re: The current object Bernd Paysan <bernd.paysan@gmx.de> - 2013-05-11 21:31 +0200
                Re: The current object Doug Hoffman <glidedog@gmail.com> - 2013-05-12 07:40 -0400
                Re: The current object Bernd Paysan <bernd.paysan@gmx.de> - 2013-05-14 01:10 +0200
                Re: The current object Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-05-14 03:58 -0500
                Re: The current object anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-05-14 14:51 +0000
                Re: The current object Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-05-15 03:48 -0500
                Re: The current object Bernd Paysan <bernd.paysan@gmx.de> - 2013-05-14 18:37 +0200
                Re: The current object Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-05-14 14:42 -0500
                Re: The current object Bernd Paysan <bernd.paysan@gmx.de> - 2013-05-15 00:22 +0200
                Re: The current object Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-05-15 02:56 -0500
                Re: The current object stephenXXX@mpeforth.com (Stephen Pelc) - 2013-05-15 13:52 +0000
                Re: The current object Bernd Paysan <bernd.paysan@gmx.de> - 2013-05-15 17:58 +0200
                Re: The current object albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-05-17 14:01 +0000
                Re: The current object johno <email@address.com> - 2013-05-15 22:38 +0100
                Re: The current object Doug Hoffman <glidedog@gmail.com> - 2013-05-14 06:27 -0400
              Re: The current object albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-05-09 16:06 +0000
      Re: The current object (was: Went open source with my GA144 ...) anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-05-06 16:12 +0000
        Re: The current object (was: Went open source with my GA144 ...) Alex McDonald <blog@rivadpm.com> - 2013-05-06 10:25 -0700
        Re: The current object (was: Went open source with my GA144 ...) Bernd Paysan <bernd.paysan@gmx.de> - 2013-05-07 04:00 +0200
          Re: The current object (was: Went open source with my GA144 ...) anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-05-07 15:02 +0000
        Re: The current object (was: Went open source with my GA144 ...) Bernd Paysan <bernd.paysan@gmx.de> - 2013-05-07 04:09 +0200
          Re: The current object Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-05-07 03:41 -0500
            Re: The current object Bernd Paysan <bernd.paysan@gmx.de> - 2013-05-07 19:02 +0200
          Re: The current object (was: Went open source with my GA144 ...) anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-05-07 14:33 +0000
            Re: The current object (was: Went open source with my GA144 ...) Bernd Paysan <bernd.paysan@gmx.de> - 2013-05-07 19:40 +0200
  Re: The current object Bernd Paysan <bernd.paysan@gmx.de> - 2013-05-15 16:46 +0200
    Re: The current object Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-05-15 13:11 -0500
      Re: The current object Bernd Paysan <bernd.paysan@gmx.de> - 2013-05-15 23:23 +0200
        Re: The current object Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-05-16 02:24 -0500
          Re: The current object anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-05-16 13:55 +0000
          Re: The current object Bernd Paysan <bernd.paysan@gmx.de> - 2013-05-16 17:45 +0200
            Re: The current object Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-05-18 05:13 -0500
              Re: The current object Doug Hoffman <glidedog@gmail.com> - 2013-05-18 06:43 -0400
              Re: The current object Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-05-18 10:03 -0500
                Re: The current object Doug Hoffman <glidedog@gmail.com> - 2013-05-18 11:30 -0400
                Re: The current object Bernd Paysan <bernd.paysan@gmx.de> - 2013-05-19 01:20 +0200
                Re: The current object Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-05-19 12:33 -0500
              Re: The current object Bernd Paysan <bernd.paysan@gmx.de> - 2013-05-19 01:07 +0200
                Re: The current object Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-05-19 03:58 -0500
      OO dispatch (was: The current object) anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-05-16 14:07 +0000
        Re: OO dispatch Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-05-18 05:28 -0500
          Re: OO dispatch anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-05-20 11:28 +0000
            Re: OO dispatch Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-05-20 09:00 -0500
              Re: OO dispatch Bernd Paysan <bernd.paysan@gmx.de> - 2013-05-21 01:37 +0200
                Re: OO dispatch Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-05-21 03:21 -0500
              Re: OO dispatch anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-05-21 12:24 +0000
                Re: OO dispatch Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-05-21 10:18 -0500
                Re: OO dispatch anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-05-21 16:03 +0000
                Re: OO dispatch Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-05-21 12:55 -0500
                Re: OO dispatch Bernd Paysan <bernd.paysan@gmx.de> - 2013-05-29 00:00 +0200
                Re: OO dispatch Mark Wills <markrobertwills@yahoo.co.uk> - 2013-05-28 15:49 -0700

csiph-web