The flyweight pattern
The flyweight pattern is used to handle a large number of fine-grained objects efficiently by sharing memory for similar/same objects.
A good example of this involves handling strings. In the field of data science, we frequently need to read and analyze a large amount of data that is represented in a tabular format. In many cases, certain columns may contain a large number of strings that are just repeated values. For example, a population survey might have a column stating gender, and so it will contain either Male or Female.
Unlike some other programming languages, strings are not interned in Julia. This means that 10 copies of the word Male are going to be stored repeatedly, occupying 10 times the memory space that ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access