i am working with my aged twin on optimizing the memory usage of a rather process that reads records out of several large files, makes sense of each record, and lobs each into a database (a very rough outline). each record has 4 ids that map to database entities. easy enough, nhibernate has an identity map (Fowler!) built in to handle duplicate references and presumably bypass unnecessary calls to the database.
turns out i'm not sure about all that. using the visual studio profiler, we noticed that an inordinate amount of time was spent in the nhibernate lookup. by simply switching to a custom dictionary (hashmap), we more than halved the lookup time. not sure how deeply i'll investergate this oddity, but if i need more performance, it may be one of the places i check first.