[MDEV-23002] Replace bool's with bitmaps in Item and THD Created: 2020-06-24  Updated: 2021-06-23  Resolved: 2021-06-23

Status: Closed
Project: MariaDB Server
Component/s: Data types
Fix Version/s: 10.6.1

Type: Task Priority: Minor
Reporter: Michael Widenius Assignee: Michael Widenius
Resolution: Fixed Votes: 1
Labels: None

Attachments: File bit.diff     File item-bit.diff    

 Description   

Replace bool in Item and THD with bitmap.

In THD and Item (the base class) we have a lot of bool variables.
We should try to replace these with a bitmap to save space
(and allow the compiler to clear/set several variables with one memory access)

in my_tree.h we have an example bitmap of how to do it:

  uint32 count:31,
	        colour:1;

I think it's ok to use ulonglong variables for the bitmaps.

It's ok to to also group variables in THD and Item so that all variables of the same size are together (this will save space as there is less holes between variables). However variables that
are obviously used together should be kept together (to get better memory caching).

As part of the task is to do:

  • Run gdb and check the sizeof before and after on THD and some Item.
  • Check the size of the mysqld binary before and after the change
  • run sql-bench test and record the changes before and after the change
  • Ask Axel (at the benchmark team) to run a simple benchmark to verify the change
    All of the above results should be added to this Jira entry and be checked by the reviewer before approving this task..
    (I don't expect any notable performance impact)


 Comments   
Comment by Oleksandr Byelkin [ 2020-06-29 ]

I added my approach for LEX & Co for 10.6 (bit.diff) fize is following:

  old new delta
THD 26392 26336 56
LEX 7080 6920 160
SELECT_LEX 1120 1088 32
SELECT_LEX_UNIT 2048 2016 32
Comment by Dan Solodko [ 2020-08-17 ]

Binary size (byte) 307 718 856 -> 301 845 608 5 873 248
Class sizes changes and sql-bench test results you can find at the following Google Doc (before and after):
https://docs.google.com/spreadsheets/d/1lunCRHZO-Z9_Spc__c0C6l58PtEHln7SFO3Au-wnrDE/edit?usp=sharing

Comment by Michael Widenius [ 2021-06-23 ]

I tried first to use bitmaps, but the compiler (gcc 7.x) did output so bad code when assigning multiple bits in a row, so it was not usable.
In the end, I used two uint8, with enum to make it type safe, to store 11 bool variables, with a lot to spare for future bools.

The whole history of trying bit and then moving to explicit bit handling is recorded in the 10.6 tree.

Comment by Michael Widenius [ 2021-06-23 ]

Pushed to 10.6.1

Generated at Thu Feb 08 09:19:06 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.