Repository: microsoft/garnet
File: libs/storage/Tsavorite/cs/src/core/Index/Tsavorite/Tsavorite.cs (C#)

Code before:
            {
                bool is_bucket_in_ofb_table = false;
                List<int> tags = new();
                int total_valid_records_in_this_bucket_cnt = 0;
                int total_valid_entries_in_ofb_in_this_bucket_cnt = 0;
                HashBucket b = *(ptable_ + bucket);
                while (true)
                {
                    // per bucket calculate the number of zero'd out slots
                    int zeroed_out_slots = 0;
                    for (int bucket_entry = 0; bucket_entry < Constants.kOverflowBucketIndex; ++bucket_entry)
                    {
                        var x = default(HashBucketEntry);
                        x.word = b.bucket_entries[bucket_entry];

                        total_entries_with_tentative_bit_set += x.Tentative ? 1 : 0;

                        if (((!x.ReadCache) && (x.Address >= beginAddress)) || (x.ReadCache && (x.AbsoluteAddress >= readCacheBase.HeadAddress)))
                        {
                            if (tags.Contains(x.Tag) && !x.Tentative)
                                throw new TsavoriteException("Duplicate tag found in index");
                            tags.Add(x.Tag);
                            ++total_valid_records_in_this_bucket_cnt;
                            ++total_record_count;
                        }
                        else if (x.word != default && x.Address < beginAddress)
                        {
                            if (is_bucket_in_ofb_table)
                                ++total_entries_in_ofb_below_begin_address;

                            ++total_entries_below_begin_address;
                        }
                        else
                        {
                            ++zeroed_out_slots;
                        }

                        if (is_bucket_in_ofb_table)
                            total_valid_entries_in_ofb_in_this_bucket_cnt++;
                    }

                    total_zeroed_out_slots += zeroed_out_slots;

                    if (is_bucket_in_ofb_table)
                    {
                        if (!slots_unused_by_buckets_ofb_histogram.ContainsKey(zeroed_out_slots))
                            slots_unused_by_buckets_ofb_histogram[zeroed_out_slots] = 0;
                        slots_unused_by_buckets_ofb_histogram[zeroed_out_slots]++;
                    }
                    else
                    {

Review comment (performance):
The && part should be unneeded bc we verified beginAddress above; also it doesn't check the readCache case. If there was some reason an additional check was needed it should be inside the "if (!default)" case, to avoid mistakenly incrementing the zeroed_out_slots below

Code after:
            {
                bool is_bucket_in_ofb_table = false;
                List<int> tags = new();
                int total_valid_records_in_this_bucket_cnt = 0;
                int total_valid_entries_in_ofb_in_this_bucket_cnt = 0;
                HashBucket b = *(ptable_ + bucket);
                while (true)
                {
                    // per bucket calculate the number of zero'd out slots
                    int zeroed_out_slots = 0;
                    for (int bucket_entry = 0; bucket_entry < Constants.kOverflowBucketIndex; ++bucket_entry)
                    {
                        var x = default(HashBucketEntry);
                        x.word = b.bucket_entries[bucket_entry];

                        if (x.Tentative)
                            ++total_entries_with_tentative_bit_set;

                        if (((!x.ReadCache) && (x.Address >= beginAddress)) || (x.ReadCache && (x.AbsoluteAddress >= readCacheBase.HeadAddress)))
                        {
                            if (tags.Contains(x.Tag) && !x.Tentative)
                                throw new TsavoriteException("Duplicate tag found in index");
                            tags.Add(x.Tag);
                            ++total_valid_records_in_this_bucket_cnt;
                            ++total_record_count;
                        }
                        else if (x.word != default)
                        {
                            if (is_bucket_in_ofb_table)
                                ++total_entries_in_ofb_below_begin_address;

                            ++total_entries_below_begin_address;
                        }
                        else
                        {
                            ++zeroed_out_slots;
                        }

                        if (is_bucket_in_ofb_table)
                            total_valid_entries_in_ofb_in_this_bucket_cnt++;
                    }

                    total_zeroed_out_slots += zeroed_out_slots;

                    if (is_bucket_in_ofb_table)
                    {
                        if (!slots_unused_by_ofb_buckets_histogram.ContainsKey(zeroed_out_slots))
                            slots_unused_by_ofb_buckets_histogram[zeroed_out_slots] = 0;
                        slots_unused_by_ofb_buckets_histogram[zeroed_out_slots]++;
                    }
                    else