Comments (3)
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.
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.
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)
- unused parameters in the empty.ts are causing TypeScript check errors HOT 6
- Global `Object` is not referenced when there is a message named Object. HOT 2
- Proto2 required fields are not serialized when they are the default value HOT 3
- Is this compiling error could be turned off by Typescript or Option in protobuf-ts HOT 2
- 2.9.2 not working with 'exactOptionalPropertyTypes: true' HOT 1
- Release 2.9.3 breaks serialization for me HOT 6
- Generated message classes cannot be subclassed because of missing 'export' HOT 1
- Error decoding from binary: "cant skip wire type 4" HOT 1
- How to debug INVALID_ARGUMENT? HOT 1
- Missing headers on RPCError HOT 8
- rpcError cannot support Chinese
- [Request] Flag to handle google wrapper types HOT 1
- Vite cannot found module HOT 2
- Invalid typescript in descriptor.ts HOT 2
- Can't retry request after awaiting response HOT 2
- Typesafe API to retrieve enums from strings HOT 4
- `output_javascript` no longer emits `.d.ts` files HOT 6
- Request: Support for moduleResolution "nodenext" and "node16" HOT 2
- Fails to download v27.0-rc1 (which was just released) HOT 7
- invalid url for latest v27.0-rc1 release HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from protobuf-ts.