frontpage.
newsnewestaskshowjobs

Open Source @Github

fp.

Open in hackernews

Ask HN: Why serialize documents to disk instead of memory-mapping runtime state?

3•ShengATsao•1d ago
Opening files like docx requires heavy string parsing and pointer allocation. After an OS swaps active RAM pages out as to flash disk as virtual memory, it can restore them almost instantly. Using 2X more flash disk space is worth if we can achieve millisecond loads. Why hasn't direct memory dumping/reloading replaced file parsing for complex document models?

I started a company in 2000 to build a commercial cross-platform desktop suite in Java. To achieve seamless live-data-linking across text, sheets and slides, we stored data objects into a 3D coordinate space (Sheet_Num,Row_Num,Column_Num) and reference/access them instead of pointers. This scheme enable us open a 50,000-pages document in 8 seconds, compared to 300+ seconds by a competing suite requiring parsing andan array of pointer construction.

Recently, some suggested that our 3D design without referencing data by pointers can possibly use OS provided mmap to restore back the entire document image as loaded into the RAM to flash disk. Instead of opening the file again with all those parsing/pointer-building work, the memory mapped buffers can be simply be brought back into RAM in milliseconds.

Our senior engineers have confirmed the feasibility and tries to prove it, but, they have encountered numerous problems to save using OpenJDK and CRaC on Linux. They told me that OpenSDK has stated that it can be done but probably did not test this part thoroughly because they never expected it be actually used.

Has any one successfully decouple a complex document substrate into off-heap memory to achieve true zero-copy mmap load or does the JVM runtime always get in the way?

Comments

verdverm•1d ago
So we can share them with each other? Are we going to pass around memory dumps instead? What about tool choice when working on a specific document format?
jamwise•1d ago
Serializing has many uses.

- Memory might not look the same on all platforms, if your app is multi-platform you stop being able to share your data cross-platform.

- The internal data structures of your app will absolutely change as your app evolves, the binary data in memory is a raw result of your data structures. So you have to commit to never changing data structures, or create complicated binary migration tools to update memory when your app updates.

- Debugging corrupted memory is incredibly tedious any sometimes impossible. Having plain text serialized data makes debugging much more straightforward.

Top my my head I would suggest to focus more on improving performance on your serialization pipeline. There might be some subset of your data that is unlikely to ever change and is identical on all platforms, maybe your serializer is hybrid in that case.

gavinray•1d ago
When you use RandomAccessFile API in JVM one of the flags allows you to mmap the contents

        try (RandomAccessFile file = new RandomAccessFile("example.dat", "rw");
             FileChannel channel = file.getChannel()) {
            
            // Map the file into memory from position 0 up to bufferSize
            MappedByteBuffer buffer = channel.map(FileChannel.MapMode.READ_WRITE, 0, bufferSize);
Once you have a mappedbytebuffer you can use MemoryLayout from FFM to view it as structured data without deserializing
mac3n•1d ago
Be careful!

I hear the old Microsoft Word save files used memory dumps, which became an undocumented nightmare of a file format.

You need total control over memory layout of the saved runtime state. No hidden fields. No pointers either - you want to be able to reload at another address. Sooner or later, you might want to add some state, and you'd need a place to put it.

That said, I have used mmap something like this, mostly so state (data) could be paged in on demand.

Neovim have a ~$800k Bitcoin donation sitting untouched since 2023

147•jakemanger•1h ago•42 comments

Ask HN: What are you working on? (September 2026)

373•david927•3d ago•1181 comments

Open-sourced jev architecture last year with model,paper and dataset

13•nandakishor_ml•7h ago•4 comments

Ask HN: What is the most career altering course or book you have gone through?

13•learner_yearner•1d ago•15 comments

Can I get insurance for company renting humanoids for parties?

2•cpsk•14h ago•14 comments

Zuck's bot increased our Vercel bill 10x

6•Marciok•15h ago•4 comments

Ask HN: Lesser known features of macOS/iPadOS/iOS/etc. 27

14•lucasoshiro•1d ago•8 comments

Ask HN: How are you managing aging relatives passwords?

12•rylando•2d ago•17 comments

Is anyone else losing their motivation to nerd out and tinker because of AI?

12•rizsyed1•1d ago•36 comments

Ask HN: Are 80s high school hobby programmers overwhelmingly pro-AI?

16•amichail•2d ago•38 comments

We struggled with DevOps, so built a open source agentic platform just for this

2•abmuhammadhamza•1d ago•0 comments

Tell HN: iOS 27 does not allow Apple Intelligence to be disabled

73•nunez•2d ago•29 comments

Started Learning Pentesting

3•muzan•2d ago•1 comments

A mnemonic-free wallet where the private key never leaves the phone's TEE

3•niumeta_TZ•1d ago•0 comments

Ask HN: Why serialize documents to disk instead of memory-mapping runtime state?

3•ShengATsao•1d ago•4 comments

Ask HN: Slow OpenAI Inference on AWS Bedrock

2•timedude•1d ago•2 comments

Ask HN: What default model do you use and why?

61•stikit•4d ago•107 comments

Ask HN: What would make you trust an AI's assessment of your understanding?

4•Aditya_0315•2d ago•3 comments

Day 13. Three production applications on AWS down

4•alt_tab•1d ago•3 comments

You've reached the end!