symtab: use longjmp() for errors and avoid intermediate table.

We used to use a separate "add table" during the upb_symtab_addfile()
operation to make it easier to back out the file if it contained
errors. But this created unnecessary work of re-adding the same symbols
to the main symtab once everything was validated.

Instead we directly add symbols to the main symbols table. If there is
an error in validation, we remove precisely the set of symbols that
were already added.

This also requires using a separate arena for each file. We can fuse
it with the symtab's main arena if the operation is successful.

LoadDescriptor_Upb                   61.2µs ± 4%  53.5µs ± 1%  -12.50%  (p=0.000 n=12+12)
LoadAdsDescriptor_Upb                4.43ms ± 1%  3.06ms ± 0%  -31.00%  (p=0.000 n=12+12)
LoadDescriptor_Proto2                 257µs ± 0%   259µs ± 0%   +1.00%  (p=0.000 n=12+12)
LoadAdsDescriptor_Proto2             13.9ms ± 1%  13.9ms ± 1%     ~     (p=0.128 n=12+12)
pull/13171/head
Joshua Haberman 4 years ago
parent 4d9a8cd67b
commit c9f9668234
  1. 14
      tests/bindings/lua/test_upb.lua
  2. 793
      upb/def.c

@ -512,6 +512,20 @@ function test_foo()
assert_equal(set.file[1].name, "google/protobuf/descriptor.proto")
end
function test_descriptor_error()
local symtab = upb.SymbolTable()
local file = descriptor.FileDescriptorProto()
file.name = "test.proto"
file.message_type[1] = descriptor.DescriptorProto{
name = "ABC"
}
file.message_type[2] = descriptor.DescriptorProto{
name = "BC."
}
assert_error(function () symtab:add_file(upb.encode(file)) end)
assert_nil(symtab:lookup_msg("ABC"))
end
function test_gc()
local top = test_messages_proto3.TestAllTypesProto3()
local n = 100

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save