Giter VIP home page Giter VIP logo

Comments (3)

timostamm avatar timostamm commented on June 6, 2024

Oh I guess it's because non-const enum would not be replaced by a value and consumes more bytes.

Exactly.

Replacing "kind" string literals:

I was about to replace the union type "scalar" | "map" | "enum" | "message" with an enum - then I was made aware of the const enum problem and I left it as is.

I think the most consistent improvement would be to actually use an enum:

export enum FieldKind {
  SCALAR, MAP, ENUM, MESSAGE
}

The generated field information could use the same pseudo-inlined code:

kind: 1 /*FieldKind.SCALAR*/

This would save quite some bytes in the generated code. It would add some bytes to the runtime, because string literals "scalar" would need to be replaced with FieldKind.SCALAR. But maybe there are some ways around it.

Maybe an other idea would be to create locale (i.e. not exported) const enum in this file - I am not sure if this would work with react though ?

Not sure either. But this could be a good general approach that could be used internally within the runtime (there are many references to the non-const ScalarType and many references to the field kind union type).

An other possible optimization could be to skip the no if equal to the index (+1) in the table, i.e.

Good point. Not sure if worth it though, because it is quite convenient to be able to lookup a field by number in the code.

from protobuf-ts.

vicb avatar vicb commented on June 6, 2024

Thanks for the detailed answer.

An other possible optimization could be to skip the no if equal to the index (+1) in the table, i.e.

Good point. Not sure if worth it though, because it is quite convenient to be able to lookup a field by number in the code.

The idea here is that the runtime would add the no property when no present (by inferring the value from the index).

from protobuf-ts.

timostamm avatar timostamm commented on June 6, 2024

The idea here is that the runtime would add the no property when no present (by inferring the value from the index).

normalizeFieldInfo() takes partial field info, but has no information about the current index. Also, field numbers are arbitrary. It is best practice to keep a sequence, but in the real world, there are often gaps or numbers out of order. Seems quite a lot of work for rather little gain.

Opening new ticket for "Replacing kind string literals".

Thanks for the feedback!

from protobuf-ts.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.