Yr12 Journal 27

In Term 4 Week 4, I was busy on completing my English presentation. However, I also followed up my plan, that is to work on the powerpoint slides of the project. Meanwhile, I also optimised the performance of my C# high performance repository.

Progress

School work

I’ve started doing my slides for a bit, and I will be able to submit it by Week 5 Friday. I did like 6 slides. However, I don’t know what should I put for the evidence because it is incomplete. But I will submit it in 5 days so we will see.

C# project

Once again, I’m addicted to opimisations. I optimised the performance of deserialising by 50% (from 150ms to 100ms for the same test case).

Basically it just access the memory faster: d2aa804

I used the [In] Attribute to compile codes that directly acces the numbers as the index to access the buffer. Also, I did 804944b:

1
2
3
4
5
6
7
8
9
10
11
public T this[in int index]
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => Data[index];
[MethodImpl(MethodImplOptions.AggressiveInlining)]
set
{
EnsureCapacity(in index);
Data[index] = value;
}
}

These optimisations only enhanced the performance by 10%, as it allows a more dirrect access to the indexer without value copies.

To make further optimisations, I realised there is no need to check the capacity of the buffer while reading (deserialising), therefore the following commit was pushed 2bf8c82:

I did not create a variable when I need to get a pin for the position of the buffer, instead I used a reference, so it will not have any value copies or creating variables.

1
ref var pin = ref *(buffer.Data + position);

and then I just returned a value of T from this pointer reference:

1
return Unsafe.ReadUnaligned<T>(ref pin); //which is basically return *(T*)&pin;

Also, instead of using indexer to access pointer element, I used add on pointer directly:

1
2
3
4
5
6
7
8
9
10
11
public T this[in int index]
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => *(Data + index);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
set
{
EnsureCapacity(in index);
*(Data + index) = value;
}
}

Overall, I achieved a 50% (or even more) optimised deserialising function.

Challenges

There were no challenges this week besides English presentation annoys me a lot.

Reflection

This week I’ve done well. I’ve done a lot of work related to IT. And I succesffuly optimised my project. Moreover, I heard I came first place in the YICTE comp. Which makes me really glad. I feel like I used this week wisely.

Timeline

I stayed on my plan this week, and almost finished the whole assignment. I already submitted the project itself, and I will be able to submit the presentation slides by Friday next week.