vortex icon indicating copy to clipboard operation
vortex copied to clipboard

Reconsider EncodingRef

Open a10y opened this issue 1 year ago • 0 comments

Currently we pass around EncodingRef to represent an encoding. It's type-defed to be a &'static dyn Encoding.

Most of our encodings are zero-sized structs, so this is pretty trivial to create. There are also a relatively small number of builtin encodings.

However, with #886 we added an OpaqueEncoding. This one actually is not zero-sized, but takes a u16 to keep track of the (unknown) encoding ID that it wraps. Instances are dynamically created in response to unknown encodings encountered in deserialization, and currently to keep with EncodingRef, we need to Box::leak to get the static reference.

There are a few alternatives

  • Make Context carry around a set of opaque_encodings. Care would need to be taken to make sure this collection is safe for concurrent updates
  • Change EncodingRef to be an Arc<dyn Encoding>. This will create an allocation for the builtin encodings whereas now there are none. However, there are only 25 builtin encodings, not that much to be allocating.

a10y avatar Sep 20 '24 23:09 a10y