-
Notifications
You must be signed in to change notification settings - Fork 117
V2: Avoid JIT deoptimizations #836
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -158,19 +158,18 @@ export function readField( | |
readListField(message, reader, options, field, wireType); | ||
break; | ||
case "map": | ||
// eslint-disable-next-line no-case-declarations | ||
const [key, val] = readMapEntry(field, reader, options); | ||
message.setMapEntry(field, key, val); | ||
readMapEntry(message, field, reader, options); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoiding an eager bailout here. |
||
break; | ||
} | ||
} | ||
|
||
// Read a map field, expecting key field = 1, value field = 2 | ||
function readMapEntry( | ||
message: ReflectMessage, | ||
field: DescField & { fieldKind: "map" }, | ||
reader: BinaryReader, | ||
options: BinaryReadOptions, | ||
): [MapEntryKey, ScalarValue | ReflectMessage] { | ||
): void { | ||
let key: MapEntryKey | undefined, | ||
val: ScalarValue | ReflectMessage | undefined; | ||
const end = reader.pos + reader.uint32(); | ||
|
@@ -211,7 +210,7 @@ function readMapEntry( | |
break; | ||
} | ||
} | ||
return [key, val]; | ||
message.setMapEntry(field, key, val); | ||
} | ||
|
||
function readListField( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -784,6 +784,7 @@ function newField( | |
| keyof (DescField & { fieldKind: "list" }) | ||
| keyof (DescField & { fieldKind: "scalar" }); | ||
const field: Partial<Record<AllKeys, unknown>> = { | ||
kind: "field", | ||
proto, | ||
deprecated: proto.options?.deprecated ?? false, | ||
name: proto.name, | ||
|
@@ -792,6 +793,13 @@ function newField( | |
message: undefined, | ||
enum: undefined, | ||
presence: getFieldPresence(proto, oneof, isExtension, parentOrFile), | ||
listKind: undefined, | ||
mapKind: undefined, | ||
mapKey: undefined, | ||
delimitedEncoding: undefined, | ||
Comment on lines
+796
to
+799
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding these properties means that the JIT can use the same map. It adds some bytes to the bundle size, but that's always the trade-off. I think it's worth it here for the >10% gain. |
||
packed: undefined, | ||
longType: undefined, | ||
getDefaultValue: undefined, | ||
}; | ||
if (isExtension) { | ||
// extension field | ||
|
@@ -815,7 +823,6 @@ function newField( | |
// regular field | ||
const parent = parentOrFile; | ||
assert(parent.kind == "message"); | ||
field.kind = "field"; | ||
field.parent = parent; | ||
field.oneof = oneof; | ||
field.localName = oneof | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The resulting logs can be inspected with the deopt explorer. Seems worth keeping this script and dep.