Background
Normally when an entity is loaded in D7, the 'field_attach_load' step will load all the data from fields into the entity object.
The field_sql_storage_field_storage_load()
loads the data from all columns by default.
On a page with a view, this could happen for many entities.
Use case
We want to create a field to be used for very long html.
This content should only be loaded on specific pages where this html is actually being displayed.
Problem
We want to avoid the big html from being loaded into memory in the field_attach_load step, to avoid memory problems.
Solutions considered so far
I think we would need a custom field type with its own loading logic. I have not found any contrib solutions yet.
The obstacle seems to be the default field_attach_load logic, which always loads all the columns from the field table. I don't see a way around that.
We could store the data in a separate table, but this would need babysitting to keep the extra table in sync with the field table.
hook_field_storage_load()
? I haven't checked very far down but it feels like you could put your custom logic in there