Skip to content

NHibernate boxing #2187

Closed
Closed
@DmitryMak

Description

@DmitryMak

I noticed that NHibernate boxes value types. This applies to built-in types like System.Guid and custom structs.

class Person {         <-- mapped entity
    private Guid _id;  <-- boxed copy will be generated
    private Age _age;  <-- custom struct, boxed copy will be generated
}

After restoring a Person instance, there will be one copy of Guid and Age baked into Person (as expected of struct fields). But there will also be at least one boxed instance of Guid and Age floating around on the heap. When loading a lot of entities, NHibernate will create a significant amount of boxed values. The values will have to be collected, hopefully as part of Gen0 collection. Classes that implement IUserType (or ICompositeUserType) are forced to box because they have to return Object, e.g.:

public interface ICompositeUserType {
    Object NullSafeGet(DbDataReader dr, string[] names, ...)
    ...
}

Is this by design or is it theoretically possible to avoid boxing? And if so, are there any plans for this feature? And maybe there a better place to ask this question?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions