solettaproject / soletta

Soletta Project is a framework for making IoT devices. With Soletta Project's libraries developers can easily write software for devices that control actuators/sensors and communicate using standard technologies. It enables adding smartness even on the smallest edge devices.
http://solettaproject.org
Apache License 2.0
226 stars 109 forks source link

add sol_arena_readonly (or sol_arena_stringshare or sol_stringshare) #1012

Open barbieri opened 8 years ago

barbieri commented 8 years ago

Similar to sol_arena, this variant would keep single-instance of strings if they are read-only, saving memory.

This could be done as a new handle exclusive to read-only strings or change sol_arena from sol_ptr_vector to a sol_vector of sol_str_slice, returning the slice or its data (the data is duplicated if didn't exist in the stringshare, otherwise an existing reference is used).

In EFL we used this a lot and proved to be useful for stuff that keeps similar strings around (like key values used in our http), but the stringshare wasn't a local handle, but a global one. Shared strings were refcounted, otherwise they would never be deleted (arenas are often deleted in short time).

We use lots of read-only string in Soletta, be in HTTP parameters, be in string packets. Once they are created, they are not allowed to be modified. If we change string packets to use stringshare, for instance, we could save memory when forwarding packets (now we do get_string() -> new_string() -> packet_del(old), this would increase refcount, then decrease, keeping it at 1).

barbieri commented 8 years ago

easy to implement, but I want to see what others think about it. @bdilly, @cmarcelo