whatisgithub

What is memorypack?

cysharp/memorypack — explained in plain English

Analysis updated 2026-06-26

4,537C#Audience · developerComplexity · 2/5Setup · easy

In one sentence

An extremely fast C# serialization library that converts objects to bytes and back, running up to 200x faster than standard JSON libraries by copying raw memory layouts at compile time instead of using runtime reflection.

Mindmap

mindmap
  root((MemoryPack))
    What it does
      Binary serialization
      Object to bytes
      Zero-encoding approach
    Performance
      10x faster than JSON
      Raw memory copy
      Compile-time codegen
    Features
      Polymorphism support
      Version tolerance
      Unity IL2CPP support
    Use Cases
      Game networking
      High-throughput APIs
      Cross-platform types
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

What do people build with it?

USE CASE 1

Speed up network message serialization in a multiplayer game by replacing JSON with MemoryPack's binary format

USE CASE 2

Reduce API response latency in a high-throughput ASP.NET Core service by switching from System.Text.Json to MemoryPack

USE CASE 3

Serialize large arrays of numeric sensor data for a scientific computing pipeline in .NET with near-zero overhead

USE CASE 4

Share typed data structures between a C# backend and a TypeScript frontend using MemoryPack's generated type definitions

What is it built with?

C#.NETNuGetRoslyn

How does it compare?

cysharp/memorypackaccord-net/frameworkopserver/opserver
Stars4,5374,5444,547
LanguageC#C#C#
Setup difficultyeasymoderatehard
Complexity2/53/54/5
Audiencedeveloperdeveloperops devops

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · easy Time to first run · 5min

Requires .NET 7 or newer and C# 11, the source generator runs automatically via Roslyn at compile time.

So what is it?

MemoryPack is a C# library that converts objects to bytes and back again, a process called serialization. It is built specifically for speed, and its benchmark results show it running ten times faster than the widely-used System.Text.Json library for typical objects and fifty to two hundred times faster for arrays of simple data types like numbers. The author previously built other popular C# serializers, and MemoryPack represents their fourth attempt, this time designed from the ground up around features introduced in .NET 7 and C# 11. The core idea behind its speed is what the README calls zero-encoding: rather than converting data into an intermediate format with extra tags and length markers the way most serializers do, MemoryPack copies the raw memory layout of C# objects directly into the output bytes when possible. This works especially well for arrays of plain numeric or value types, which are already stored in memory in a flat, compact way. For more complex objects the library uses code generation, meaning it writes specialized serialization code at compile time rather than figuring out what to do at runtime through reflection. This avoids a common performance cost that other libraries pay every time they run. Setting it up is straightforward for developers. You add the NuGet package, mark your class or struct with a MemoryPackable attribute, and call two methods to serialize and deserialize. The library supports a wide range of built-in types including all standard collections, dictionaries, date and time types, and common .NET value types. It also handles more advanced scenarios like polymorphism (where a field can hold different object types), circular references within object graphs, version tolerance so older and newer data formats can coexist, and streaming for processing data in chunks. The library also supports Unity game development through the IL2CPP compilation path, and it can generate TypeScript type definitions and an ASP.NET Core formatter for use in web APIs. The full README is longer than what was shown.

Copy-paste prompts

Prompt 1
I have a C# record class I want to serialize with MemoryPack instead of System.Text.Json. Show me how to add the [MemoryPackable] attribute and write the serialize and deserialize calls.
Prompt 2
How do I use MemoryPack version tolerance so I can add new fields to my C# class without breaking deserialization of data saved with an older version?
Prompt 3
Set up MemoryPack in a Unity project targeting IL2CPP. What changes do I need to make to my serializable classes compared to a regular .NET project?
Prompt 4
Generate TypeScript type definitions from my MemoryPack C# model classes for a web frontend that communicates with my ASP.NET Core API.
Prompt 5
How do I serialize a polymorphic type hierarchy with MemoryPack where a base class field can hold different subclass instances at runtime?

Frequently asked questions

What is memorypack?

An extremely fast C# serialization library that converts objects to bytes and back, running up to 200x faster than standard JSON libraries by copying raw memory layouts at compile time instead of using runtime reflection.

What language is memorypack written in?

Mainly C#. The stack also includes C#, .NET, NuGet.

How hard is memorypack to set up?

Setup difficulty is rated easy, with roughly 5min to a first successful run.

Who is memorypack for?

Mainly developer.

Open on GitHub → Ask about another repo

This repo across BitVibe Labs

Verify against the repo before relying on details.