std.data.json formal review

Dmitry Olshansky via Digitalmars-d digitalmars-d at puremagic.com
Tue Aug 18 09:56:14 PDT 2015


On 18-Aug-2015 19:35, Andrei Alexandrescu wrote:
> On 8/18/15 12:31 PM, Dmitry Olshansky wrote:
>> On 18-Aug-2015 16:19, Andrei Alexandrescu wrote:
>>> On 8/18/15 2:55 AM, Dmitry Olshansky wrote:
>>>> On 18-Aug-2015 01:33, Andrei Alexandrescu wrote:
>>>>> On 8/17/15 2:47 PM, Dmitry Olshansky wrote:
>>>>>>
>>>>>> Actually one can combine the two:
>>>>>> - use integer type tag for everything built-in
>>>>>> - use pointer tag for what is not
>>>>>
>>>>> But a pointer tag can do everything that an integer tag does. --
>>>>> Andrei
>>>>
>>>> albeit quite a deal slooower.
>>>
>>> I think there's a misunderstanding. Pointers _are_ 64-bit integers and
>>> may be compared as such. You can use a pointer as an integer. -- Andrei
>>>
>>
>> Integer in a small range is faster to switch on. Plus comparing to zero
>> is faster, so if the common type has tag == 0 it's a net gain.
>
> Agreed. These are small gains though unless tight loops are concerned.
>
>> Strictly speaking pointer with vtbl is about as fast as switch but when
>> we have to switch on 2 types the vtbl dispatch needs to be based on 2
>> types instead of one. So ideally we need vtbl per pair of type to
>> support e.g. fast binary operators on TaggedAlgebraic.
>
> But I'm talking about using pointers for indirect calls IN ADDITION to
> using pointers for simple integral comparison. So the comparison is not
> appropriate. It's better to have both options instead of just one.
>

If common type fast path with 0 is not relevant then the only gain of 
integer is being able to fit it in a couple of bytes or even reuse some 
vacant bits.

Another thing is that function addresses are rather sparse so switch 
statement should do some special preprocessing to make it more dense:
  - subtract start of the code segment (maybe, but this won't work with 
DLLs though)
  -  shift right by 2(4?) as functions are usually aligned

-- 
Dmitry Olshansky


More information about the Digitalmars-d mailing list