perf: Intern strings to reduce memory usage
This interning logic is not highly efficient, but it still reduces RSS noticeably.
I verified that there were too many duplicates in the case of bundler (not in same sourcemap, rather in multiple source maps). The problem is that a bundler intentionally duplicates some modules into multiple chunks. It's for faster loading of JS bundles, so I think all bundlers share this problem.
That makes sense.
Its quite interesting that some of our methods take a T: Into<Arc<str>>, which means you can pass it a Arc<str> and it will just Into it, which is a trivial operation.
Not so for the source_content though.
I guess my point with that is that if the bundler internally is using Arc<str>, you could pass those around instead without cloning the actual file contents. Does that make sense?
If that would help, we could just make the source_content take a T: Into<Arc<str>> as well.
I think it makes sense.
For turbopack, we store source texts in another form, which cannot be converted to Arc<str> in a cheap way but it could be useful for other users.
I think the interning should be improved to make entries live a bit longer, but not sure about a way to do it.
I found a better solution for this problem, so I'm closing this.