Skip to content
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

*: use lite runtime #366

Merged
merged 8 commits into from Mar 22, 2019
Merged

*: use lite runtime #366

merged 8 commits into from Mar 22, 2019

Conversation

BusyJay
Copy link
Contributor

@BusyJay BusyJay commented Mar 12, 2019

We have never used any features that requires reflection, so use a lite runtime. On my machine, lite runtime compiles faster, and release compile times of TiKV changes from 15 minutes to 13 minutes.

I will check whether TiDB/PD/TiSpark requires full runtime later.

@BusyJay
Copy link
Contributor Author

BusyJay commented Mar 12, 2019

According to golang/protobuf#788, optimize_for is ignored in golang, so it should not be a problem.

siddontang
siddontang previously approved these changes Mar 12, 2019
Copy link
Member

@siddontang siddontang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am surprised that this can reduce compiling time, cool job.

LGTM

@ngaut
Copy link
Member

ngaut commented Mar 12, 2019

Cool, LGTM

ngaut
ngaut previously approved these changes Mar 12, 2019
@ilovesoup
Copy link

It seems this optimization breaks Java code.

[libprotobuf WARNING ../../src/google/protobuf/compiler/java/java_file.cc:228] The optimize_for = LITE_RUNTIME option is no longer supported by protobuf Java code generator and may generate broken code. It will be ignored by protoc in the future and protoc will always generate full runtime code for Java. To use Java Lite runtime, users should use the Java Lite plugin instead. See:
  https://github.com/google/protobuf/blob/master/java/lite.md

Currently TiSpark pins to a specific version of kvproto and integration tests pulls latest version of TiDB bundle making sure that TiSpark still works with latest TiDB. So this PR will not break TiSpark instantly. However, protobuf is not only used in TiSpark, but also all other places in the platform. Instead of carefully shade it with a specific LITE version, I'd rather simply use a script removing the line while building.

@ilovesoup
Copy link

@flowbehappy please take a look at TiFlash part.

brson
brson previously approved these changes Mar 13, 2019
Copy link

@brson brson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice find @BusyJay !

@flowbehappy
Copy link

It breaks the build process of TiFlash, which is a CPP project. We should reconsider if this PR is suitable. According to document:

Generated classes will only implement the MessageLite interface in each language, which provides only a subset of the methods of the full Message interface.

Here is the error log:

In file included from /Users/flow/workspace/github/theflash/storage/ch/contrib/kvproto/cpp/kvproto/enginepb.grpc.pb.cc:6:
In file included from /Users/flow/workspace/github/theflash/storage/ch/contrib/kvproto/cpp/kvproto/enginepb.grpc.pb.h:9:
In file included from /usr/local/include/grpcpp/impl/codegen/async_generic_service.h:22:
In file included from /usr/local/include/grpcpp/impl/codegen/async_stream.h:22:
/usr/local/include/grpcpp/impl/codegen/call.h:307:19: error: implicit instantiation of undefined template 'grpc::SerializationTraits<enginepb::CommandRequestBatch, void>'
Status result = SerializationTraits<M, void>::Serialize(
^
/usr/local/include/grpcpp/impl/codegen/sync_stream.h:505:14: note: in instantiation of function template specialization 'grpc::internal::CallOpSendMessage::SendMessageenginepb::CommandRequestBatch' requested here
if (!ops.SendMessage(msg, options).ok()) {
^
/usr/local/Cellar/llvm@6/6.0.1/include/c++/v1/memory:2285:5: note: in instantiation of member function 'grpc::ClientReaderWriter<enginepb::CommandRequestBatch, enginepb::CommandResponseBatch>::Write' requested here
delete __ptr;
^
/usr/local/Cellar/llvm@6/6.0.1/include/c++/v1/memory:2598:7: note: in instantiation of member function 'std::__1::default_delete<grpc::ClientReaderWriter<enginepb::CommandRequestBatch, enginepb::CommandResponseBatch> >::operator()' requested here
_ptr.second()(__tmp);
^
/usr/local/Cellar/llvm@6/6.0.1/include/c++/v1/memory:2552:19: note: in instantiation of member function 'std::__1::unique_ptr<grpc::ClientReaderWriter<enginepb::CommandRequestBatch, enginepb::CommandResponseBatch>, std::__1::default_delete<grpc::ClientReaderWriter<enginepb::CommandRequestBatch, enginepb::CommandResponseBatch> > >::reset' requested here
~unique_ptr() { reset(); }
^
/Users/flow/workspace/github/theflash/storage/ch/contrib/kvproto/cpp/kvproto/enginepb.grpc.pb.h:67:14: note: in instantiation of member function 'std::__1::unique_ptr<grpc::ClientReaderWriter<enginepb::CommandRequestBatch, enginepb::CommandResponseBatch>, std::__1::default_delete<grpc::ClientReaderWriter<enginepb::CommandRequestBatch, enginepb::CommandResponseBatch> > >::~unique_ptr' requested here
return std::unique_ptr< ::grpc::ClientReaderWriter< ::enginepb::CommandRequestBatch, ::enginepb::CommandResponseBatch>>(ApplyCommandBatchRaw(context));
^
/usr/local/include/grpcpp/impl/codegen/serialization_traits.h:58:7: note: template is declared here
class SerializationTraits;
^

@BusyJay
Copy link
Contributor Author

BusyJay commented Mar 13, 2019

I'm working on a workaround to get it enabled only for rust. Hopefully stepancheg/rust-protobuf#399 can be merged, otherwise I guess I have to do some scripting.

@BusyJay BusyJay dismissed stale reviews from brson, ngaut, and siddontang via 5616a7a March 15, 2019 11:11
@BusyJay
Copy link
Contributor Author

BusyJay commented Mar 18, 2019

I can successfully get it compiled on my local machine, but on CI it fails. It seems cargo in CI resolves protobuf as version 2.6.0, while my local cargo resolves it as 2.0.6. Really magical. 🤔

@Hoverbear
Copy link
Contributor

Hoverbear commented Mar 18, 2019

@BusyJay Maybe this article can help us understand how some dependency resolution is done in Rust? Sometimes it's a puzzle to me too. :(

http://aturon.github.io/2018/07/25/cargo-version-selection/

Maybe it's related to the patch in the cargo.toml?

@brson
Copy link

brson commented Mar 18, 2019

The CI shouldn't be doing any crate resolution at all since the lockfile is checked in! Maybe the lockfile on this branch is not updated.

To avoid stale lockfiles in the tree I suggest running CI with --locked on every cargo command. If the build passes with --locked then you know that CI has built with the exact same deps that you did locally.

cc @zhangjinpeng1987 re adding --locked to CI invocations of cargo

@BusyJay
Copy link
Contributor Author

BusyJay commented Mar 19, 2019

I think there is a bug in cargo. After removing patch configuration, dependencies are resolved as expected. Specifically, protobuf is resolved to 2.0.6 as there is a rule '~2.0' in the Cargo.toml. But adding the patch configuration and removing Cargo.lock, grpcio ->protobuf is resolved as 2.4.

/cc rust-lang/cargo#6762

The CI shouldn't be doing any crate resolution at all since the lockfile is checked in!

No, it's not. It's a library, Cargo.lock is not expected to be checked in.

@BusyJay
Copy link
Contributor Author

BusyJay commented Mar 20, 2019

@ilovesoup @flowbehappy I use custom options to enable lite runtime now, can you check it out again?

@brson
Copy link

brson commented Mar 20, 2019

No, it's not. It's a library, Cargo.lock is not expected to be checked in.

Indeed. I thought I was looking at a tikv pr.

@flowbehappy
Copy link

LGTM 👍

@BusyJay BusyJay merged commit a637188 into pingcap:master Mar 22, 2019
@BusyJay BusyJay deleted the lite-runtime branch March 22, 2019 07:31

# TODO: use patch instead if rust-lang/cargo#6762 is resolved.
[replace]
"protobuf-codegen:2.0.6" = { git = "https://github.com/busyjay/rust-protobuf.git", branch = "customize-lite-runtime-2.0" }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nrc

can we use lite runtime in prost?

sticnarf pushed a commit to sticnarf/kvproto that referenced this pull request Oct 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants