Skip to content

Conversation

@MaxGraey
Copy link
Member

@MaxGraey MaxGraey commented Apr 7, 2018

  • Now we use full 32-bits for bitset array which store one extra bit per element.
- Now we use full 32-bits for bitset array which store one extra bit per element
@dcodeIO
Copy link
Member

dcodeIO commented Apr 7, 2018

Fwiw, at this point it appears that the maximum size of an array will eventually be limited by its backing ArrayBuffer. Effective maximum size might then become ((1 << 30) - 8) >>> alignof<T>(), with 1 << 30 being the maximum allocation size an allocator will handle in 32 bits and 8 being the header size of an ArrayBuffer plus alignment overhead. Might change again once we have GC, that is - 8 - GC_HEADER_SIZE.

@MaxGraey
Copy link
Member Author

MaxGraey commented Apr 7, 2018

This changes not concern ArrayBuffer or maximum allocation size. It just reduce memory usage for helper array, which now use more compressed view. Just example bitset in memory.
Before:

0x00 00 00 FF, 0x00 00 00 FF, 0x00 00 00 FF, 0x00 00 00 FF, ... 

After:

0xFF FF FF FF, ... 
const intShift = alignof<i32>();

var blen = (len + 7) >> 3;
var blen = (len + 31) >> 5;
Copy link
Member

@dcodeIO dcodeIO Apr 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trying to understand this change. Before, there was one byte per 8 elements (1 bit per element), if I understood this correctly:

8 elements -> blen=1
9 elements -> blen=2

Afterwards, with the change, this becomes:

8 elements -> blen=1
9 elements -> blen=1 (is this correct?)

Copy link
Member Author

@MaxGraey MaxGraey Apr 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right!

Before:
8 elements -> blen = 1
9 elements -> blen = 2

After:
8 elements -> blen = 1
9 elements -> blen = 1
32 elements -> blen = 1
33 elements -> blen = 2
64 elements -> blen = 2

So for 32 elements now used full space of 32-bit word

Copy link
Member

@dcodeIO dcodeIO Apr 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might be missing something, but my impression was that the bitset needs one bit per element? Or does it calculate the number of 32-bit ints now and blen isn't synonymous for byteLength anymore?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, bitset just add one extra bit per element.

Copy link
Member

@dcodeIO dcodeIO Apr 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, if there are 3 elements, wouldn't it need 3 distinct bits still (one per element)? Otherwise, let's say there are three elements, the bitset would be 0011b, unable to distinguish this from element 1 and 2 being set?

Or, let me rephrase: If there are 32 elements, the bitset would need 32 bits. With 8 bits per byte, that are 4 bytes, not 1?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because I hope Uint32Array is more performant. In JS version it's true

Copy link
Member

@dcodeIO dcodeIO Apr 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Than an Uint8Array? Even though an Uint32Array involves additional (obviously hard to understand ^^) shifts?

Copy link
Member Author

@MaxGraey MaxGraey Apr 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you mean Array<bool> or Array<u8> which store only one bit of 8-bits current version slower of course but we loose 7-bits and our memory usage is worst. So this is balance between memory usage/speed. I mean current version faster previous when I used 8-bit vector inside 32-bit array =)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure Array<bool> doesn't make sense because it wastes 7/8 bits, but why wouldn't u8 work, storing 8 element bits per u8, over an u32 storing 32 element bits per u32?

Copy link
Member Author

@MaxGraey MaxGraey Apr 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. That's what I wrote and older version works perfectly, but we loose 24-bits and use the same xor-shifts techniques for access to bits. Now I rewrite this to use full 32-bits range

@dcodeIO
Copy link
Member

dcodeIO commented Apr 7, 2018

Ok, going to merge this, maybe I should just try it out a bit :)

@dcodeIO dcodeIO merged commit ac2281b into AssemblyScript:master Apr 7, 2018
@dcodeIO
Copy link
Member

dcodeIO commented Apr 7, 2018

A touched a few things here to get a handle on it. Nothing special, just a bit of local caching, operation elimination, AST crunching etc. Let me know if you spot a mistake :)

@MaxGraey MaxGraey deleted the improve-sorting branch June 12, 2018 10:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants