-
Notifications
You must be signed in to change notification settings - Fork 185
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
Generate thrift code in multiple mods/files #454
Comments
I think this is a workaround for the lack of IDE and website capabilities. However, it may be worth doing. We need detailed design, especially in large-scale idl (thousands of structs, enums, etc.) to avoid IDE problems, website problems, and most importantly, naming conflicts caused by too many files, and to allow users to reference all files at once in a convenient way and maintain the namespace relationship, which will be a more troublesome part. At present, this feature does not affect normal use and is not a high priority. |
This issue becomes worse the more entites there are, with some files growing in size as large as several hunders megabyes. For the design, the solution might be simply utilizing the On most filesystems, many files in a single directory can lead to performance degradations. To workaround this problem, a separate directory can be generated for each 1_000 or 1_000_000 files. Then, the files would be included like This solution preserves the single entry point |
I think maybe we can try separating by mods first? Or if the file is still too large, we can try separating by struct/enum/service/const? For example, we have two idls // article.thrift
namespace rs article
struct Article {
1: required i64 id,
2: required string title,
3: required string content,
4: required i64 author_id,
}
struct GetArticleRequest {
1: required i64 id,
}
struct GetArticleResponse {
1: required Article article,
}
service ArticleService {
GetArticleResponse GetArticle(1: GetArticleRequest req),
}
// author.thrift
namespace rs article.author // just for example
struct Author {
1: required i64 id,
2: required string username,
3: required string email,
} In that case, we can generate the following layout:
With the following example code: // in volo_gen.rs
mod article {
include!("article/mod.rs");
}
// in article/mod.rs
include!("struct_Article.rs");
include!("struct_GetArticleRequest.rs");
include!("struct_GetArticleResponse.rs");
include!("service_ArticleService.rs");
mod author {
include!("author/mod.rs");
}
// in article/author/mod.rs
include!("struct_Author.rs"); This will result in more readable code than just generate something like Furthermore, I'm not quite familiar with how IDEs(RustRover, VSCode + rust-analyzer) deal with |
That naming scheme is better for sure, and will make exploring the generated files easier.
While there's no 100% guarantee that no performance problems will arise, the main problem I see is the actual file size. To analyze files with
A well-formed files which contain valid Rust code should be well-supported by IDEs, even if they are This generation scheme could also be optional, enabled only by an explicit flag. |
@PureWhiteWu if the issue is not a high priority for you right now, I can try implementing it, though I would probably need some guidance on some entry points. |
@missingdays Great! Thanks very much! Feel free to contact @Millione if you need any help. |
After looking around the code a bit, I noticed that there's a If I'm reading the implementation correctly, it creates a workspace with one crate for each definition. So it looks like it solves the same problem, but in a more straightforward way |
In fact, the problem we encountered comes from the both workspace and normal mode. Although the workspace mode has split at the idl level, the single idl and its dependencies are still too complicated. In addition, because we generate all common-used(used by multi idl) structures in a common library by default, the generated files in this library are very large (this is the problem we encountered when using RustRover). |
This needs a support on the |
Feature Request
Crates
volo-thrift
/pilota
Motivation
Pilota often generates all code in a single file, which can result in extremely large files when the thrift IDL is substantial.
This issue is evident in
hive_metastore
, where the generated file size approaches 10MiB. Such large files can slow down IDEs and cause web pages to crash.Try: https://docs.rs/hive_metastore/latest/src/hive_metastore/hms.rs.html#52510-52520
Proposal
Generate thrift code in multiple mods/files by
struct
/service
.Alternatives
None.
The text was updated successfully, but these errors were encountered: