Groups | Search | Server Info | Keyboard shortcuts | Login | Register
Groups > comp.lang.forth > #22600
| From | Bernd Paysan <bernd.paysan@gmx.de> |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Re: The current object |
| Date | 2013-05-15 00:22 +0200 |
| Organization | 1&1 Internet AG |
| Message-ID | <kmudfo$27i$1@online.de> (permalink) |
| References | (21 earlier) <518f7fbb$0$32105$14726298@news.sunsite.dk> <kmrrtk$8nm$1@online.de> <_Lmdnbce8uElYQzMnZ2dnUVZ_sidnZ2d@supernews.com> <kmtp8h$iof$1@online.de> <6IGdnc1P2b8tDg_MnZ2dnUVZ_ridnZ2d@supernews.com> |
Andrew Haley wrote: > Bernd Paysan <bernd.paysan@gmx.de> wrote: >> Andrew Haley wrote: >> Really? I think this is obsessive encapsulation, and probably >> originates in the "interface" concept: You define an interface, >> which is a set of selectors. And then you have various classes >> implementing that interface - as the interface itself does not have >> ivars, the classes don't share any ivars. > > Well, yes. The point is that you can't possibly know what subclasses > people have written, so if you want the flexibility to change how your > class is implemented -- and you surely do -- then you can't give > subclasses interior access. Incidentially, MINOS was developed around the discovery of substition (the point Anton made). So parts of MINOS don't follow the substition principle, but form an inheritance tree, and other parts do, and have an abstract base class and a flat hierarchy. The parts that don't (the widget classes) have a pretty fixed ivar layout, and it doesn't actually harm that they do - this ivar layout is well thought-through. The parts that do follow the substition principle have access methods, for obvious reasons. So I think it just is a design decision. If you decide to go with inheritance, you should simply consider the ivars as part of the public interface. It's no longer "modern" style to do it, which is why I don't want to repeat that design decision for MINOS 2. Composition is the key here. >> However, this is not really impossible to solve in an OOP framework: >> The interface defines the behavior, and each class can implement it >> as it likes to. > > But why? All you really need is a fast and reasonably general > dispatch machanism, like the LISP virtual function. Maybe. >> The MOP would define the interface, and the actual object system >> would define the implementation. > > That sounds far from ideal to me. Surely the Forth system itself can > do far better by using things like inline caches. You need inline caches, when a vtable dispatch isn't possible. The standard explanation why a vtable dispatch is "more costly" than an inline cache doesn't hold for contemporary processors with pattern-based branch target buffers: There, the vtable dispatch is better. And the inline cache, because it modifies an instruction on every mis-predict, does not only cause a costly branch mispredict, but an even more costly code update (inline caches use direct calls, i.e. the address is in code). However, there is one point: If you let the Forth system do it, and create some standard benchmarks to test performance, chances are high that the system implementer gives you a good performance. On current architecture, I would implement the dispatch as follows: Do a lookup from selector -> vtable offset. Do a vtable dispatch using a register for the offset. The lookup now does not need to distinguish *every* class, it can arrange classes into clusters with identical vtables. And the thing to cache and change is data. And if we know that there is no multiple inheritance for the particular class we might want to call, we can do the first lookup at compile time. I would implement the selector -> vtable offset as array access. This array would be sparse, and may return the "unknown method" offset if the lookup does not succeed. That way, you can pack the vtables of classes with the same interfaces (which you often have quite a bunch of), and don't need many of these sparse tables. The data cache is good enough to cache that lookup and jmp *(reg1+reg2) indirect branches are easy to do. You absolutely need to inline the dispatch code for performance. This would do it in four instructions, in C-like pseudo-code: class = op[-1]; // or TOS if TOS-based selector call offset = class->lookup[selector]; // these are two instructions call *(class.vtable+offset); No code update whatsoever needed, all caching happens in the CPU, which is certainly better at caching. All classes with understand the same selector set can share a lookup table. The way to implement this is to create the lookup table when you declare a class, and search for identical lookup tables, and point to them instead. > I'm pretty sure that if the Forth system itself provides fast dispatch > a la virtual functions it can do a better job. Yes. On x86, bigForth's vtable dispatch is indistinguishable from a direct call (if correctly predicted, benchmarked on Core i7; I can do about 400 million calls calling a "1 counter +!" function per second, 3.4GHz, including the loop overhead of the caller), on VFX, the advanced compiler still generates measurable slower code, because there's no infrastructure for speedup provided by the vendor. >> * We see "old and proven" arguments, which is the standard argument >> against any change. Because it implies that "new" means "unproven". > > Straw man. Forget it. Ok. -- Bernd Paysan "If you want it done right, you have to do it yourself" http://bernd-paysan.de/
Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar
The current object (was: Went open source with my GA144 ...) anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-05-01 17:01 +0000
Re: The current object (was: Went open source with my GA144 ...) albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-05-01 19:20 +0000
Re: The current object (was: Went open source with my GA144 ...) anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-05-02 17:02 +0000
Re: The current object (was: Went open source with my GA144 ...) Bernd Paysan <bernd.paysan@gmx.de> - 2013-05-02 02:12 +0200
Re: The current object Doug Hoffman <glidedog@gmail.com> - 2013-05-02 04:52 -0400
Re: The current object Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-05-02 04:31 -0500
Re: The current object Bernd Paysan <bernd.paysan@gmx.de> - 2013-05-02 18:25 +0200
Re: The current object anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-05-02 16:58 +0000
Re: The current object Bernd Paysan <bernd.paysan@gmx.de> - 2013-05-02 22:26 +0200
Re: The current object anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-05-06 14:52 +0000
Re: The current object Bernd Paysan <bernd.paysan@gmx.de> - 2013-05-07 03:47 +0200
Re: The current object anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-05-07 15:22 +0000
Re: The current object Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-05-02 12:12 -0500
Re: The current object Bernd Paysan <bernd.paysan@gmx.de> - 2013-05-02 21:56 +0200
Re: The current object Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-05-03 03:19 -0500
Re: The current object Doug Hoffman <glidedog@gmail.com> - 2013-05-03 06:54 -0400
Re: The current object (was: Went open source with my GA144 ...) anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-05-02 14:28 +0000
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