Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9201795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:06:17+00:00 2026-06-17T23:06:17+00:00

I have started work with protobuf-net library. It increased speed of serialization on 30%

  • 0

I have started work with protobuf-net library. It increased speed of serialization on 30% but I have troubles with resulting file size.

My data model is:

    [Serializable]
    [ProtoContract(SkipConstructor = true)]
    private class ReportDataItem
    {
        [ProtoMember(1)]
        public Int32 C11 { get; set; }
        [ProtoMember(2)]
        public Int32 C12 { get; set; }
        [ProtoMember(3)]
        public Int32 C13 { get; set; }
        [ProtoMember(4)]
        public Int32 C14 { get; set; }
        [ProtoMember(5)]
        public Int32 C15 { get; set; }
        [ProtoMember(6)]
        public Int32 C16 { get; set; }
        [ProtoMember(7)]
        public Int32 C17 { get; set; }
        [ProtoMember(8)]
        public Int32 C18 { get; set; }
        [ProtoMember(9)]
        public Int32 C19 { get; set; }
        [ProtoMember(10)]
        public Int32 C110 { get; set; }

        [ProtoMember(11)]
        public Int64 C21 { get; set; }
        [ProtoMember(12)]
        public Int64 C22 { get; set; }
        [ProtoMember(13)]
        public Int64 C23 { get; set; }
        [ProtoMember(14)]
        public Int64 C24 { get; set; }
        [ProtoMember(15)]
        public Int64 C25 { get; set; }
        [ProtoMember(16)]
        public Int64 C26 { get; set; }
        [ProtoMember(17)]
        public Int64 C27 { get; set; }
        [ProtoMember(18)]
        public Int64 C28 { get; set; }
        [ProtoMember(19)]
        public Int64 C29 { get; set; }
        [ProtoMember(20)]
        public Int64 C210 { get; set; }

        [ProtoMember(21)]
        public String C31 { get; set; }
        [ProtoMember(22)]
        public String C32 { get; set; }
        [ProtoMember(23)]
        public String C33 { get; set; }
        [ProtoMember(24)]
        public String C34 { get; set; }
        [ProtoMember(25)]
        public String C35 { get; set; }
        [ProtoMember(26)]
        public String C36 { get; set; }
        [ProtoMember(27)]
        public String C37 { get; set; }
        [ProtoMember(28)]
        public String C38 { get; set; }
        [ProtoMember(29)]
        public String C39 { get; set; }
        [ProtoMember(30)]
        public String C310 { get; set; }
    }

    [Serializable]
    [ProtoContract()]
    private class ReportData
    {
        [ProtoMember(1, DataFormat = DataFormat.Group)]
        public List<ReportDataItem> ReportDataItems { get; set; }
    }

    [Serializable]
    [ProtoContract()]
    private class Report
    {
        [ProtoMember(1)]
        public ReportData ReportData { get; set; }
    }

So when I try to serialize:

    private static void ObjectSerialization()
    {

const string someData = @”qtwretyfsjdabvfsjdlfudspogds;kfg;lkfdsl;gkl;dsfkgl;kdfsgr;iweprpo\z\xlvcfmxzcbvjiorsdifdlf\jl;dsa”;

            Report report = new Report();
            report.ReportData = new ReportData {ReportDataItems = new List<ReportDataItem>()};

            for (int j = 0; j < 10; j++)
            {
                ReportDataItem reportDataItem = new ReportDataItem();

                reportDataItem.C11 = j;
                reportDataItem.C12 = j;
                reportDataItem.C13 = j;
                reportDataItem.C14 = j;
                reportDataItem.C15 = j;
                reportDataItem.C16 = j;
                reportDataItem.C17 = j;
                reportDataItem.C18 = j;
                reportDataItem.C19 = j;
                reportDataItem.C110 = j;

                reportDataItem.C21 = j;
                reportDataItem.C22 = j;
                reportDataItem.C23 = j;
                reportDataItem.C24 = j;
                reportDataItem.C25 = j;
                reportDataItem.C26 = j;
                reportDataItem.C27 = j;
                reportDataItem.C28 = j;
                reportDataItem.C29 = j;
                reportDataItem.C210 = j;

                reportDataItem.C31 =someData;
                reportDataItem.C32 = someData;
                reportDataItem.C33 = someData;
                reportDataItem.C34 = someData;
                reportDataItem.C35 = someData;
                reportDataItem.C36 = someData;
                reportDataItem.C37 = someData;
                reportDataItem.C38 = someData;
                reportDataItem.C39 = someData;
                reportDataItem.C310 = someData;

                report.ReportData.ReportDataItems.Add(reportDataItem);
            }

            using (Stream stream = new FileStream(@"c:\Test\Object\0.bin", FileMode.Create, FileAccess.Write, FileShare.Write))
            {
                Serializer.Serialize(stream, report);
            }

            using (Stream stream = new FileStream(@"c:\Test\Object\bf_0.bin", FileMode.Create, FileAccess.Write, FileShare.Write))
            {
                BinaryFormatter formatter = new BinaryFormatter();
                formatter.Serialize(stream, report);
            }
}

I had results provided below:

  • protobuf-net file size 10428 Bytes
  • BinaryFormatter file size 3458 Bytes

Could you help me to find a right solution for decrease a size of result protobuf-net file.
Protobuf-net I installed as a package from VS Package Manager.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T23:06:19+00:00Added an answer on June 17, 2026 at 11:06 pm

    I changed the last few lines to:

    using (Stream stream = new FileStream(@"pb.bin", FileMode.Create,
         FileAccess.Write, FileShare.Write))
    {
        Serializer.Serialize(stream, report);
        Console.WriteLine(stream.Length);
    }
    Console.WriteLine(new FileInfo("pb.bin").Length);
    
    using (Stream stream = new FileStream(@"bf.bin", FileMode.Create,
         FileAccess.Write, FileShare.Write))
    {
        BinaryFormatter formatter = new BinaryFormatter();
        formatter.Serialize(stream, report);
        Console.WriteLine(stream.Length);
    }
    Console.WriteLine(new FileInfo("bf.bin").Length);
    

    to get the amount of data written to the stream, and the final size of the files. My results:

    1628
    1628
    3144
    3144
    

    Which looks fine to me. Please verify your data.

    Is it possible that you are using a much bigger string than “some data”? If so, there is an important question: are you likely to be duplicating the strings in real code? If you aren’t, then the BF test is invalid, because it will be using reference tracking by default, so only storing the strings once – but your real data will behave very differently. If you are going to be using the same string lots of times, then you can mimic this re-use in protobuf-net:

    [ProtoMember(21, AsReference=true)]
    public String C31 { get; set; }
    [ProtoMember(22, AsReference = true)]
    public String C32 { get; set; }
    [ProtoMember(23, AsReference = true)]
    public String C33 { get; set; }
    [ProtoMember(24, AsReference = true)]
    public String C34 { get; set; }
    [ProtoMember(25, AsReference = true)]
    public String C35 { get; set; }
    [ProtoMember(26, AsReference = true)]
    public String C36 { get; set; }
    [ProtoMember(27, AsReference = true)]
    public String C37 { get; set; }
    [ProtoMember(28, AsReference = true)]
    public String C38 { get; set; }
    [ProtoMember(29, AsReference = true)]
    public String C39 { get; set; }
    [ProtoMember(30, AsReference = true)]
    public String C310 { get; set; }
    

    The output now:

    939
    939
    3144
    3144
    

    However! This will slightly grow the output if the strings are not generally repeated, and will make it hard for other protobuf implementations to use it (it is valid protobuf data, but via some voodoo).

    The above is useful if, for example, you have things like custom names / country names / statuses etc that are represented as strings but duplicated lots.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just started work on asmall program that sends text over net (TON)
I have started using the protobuf-net lib to communication between some of the programs
I have recently started work on a large project in .net (C#) and I
I have started work on a project which uses Spring.Net, and i'm coming at
Recently I have started work on a multi-threaded console based application using VB.Net and
I have just started to work on web applications, and learning to use ASP.Net.
I have started solving the problems of http://projecteuler.net/ , but I can't seem to
Actually, i have started work on creating a web service in Python and C#(.NET
I have just started to work with Ninject 2.0 with ASP.NET MVC 2. So,
I have started to work on maven project recently. The piece of code I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.