Rust Programming

8144 readers
2 users here now

founded 6 years ago
MODERATORS
226
227
228
 
 

A simple note taking application written in Rust and GTK4.

Rnote aims to be a simple but functional note taking application for freehand drawing or annotating pictures or documents. It eventually should be able to import / export various media file formats. One main consideration is that it is vector based, which should make it very flexible in editing and altering the contents.

229
 
 

Hi! I was playing around with matrix-sdk-rust and i wrote just for fun this bot that converts twitter links into nitter ones.

230
231
2
submitted 4 years ago* (last edited 4 years ago) by nutomic@lemmy.ml to c/rust@lemmy.ml
 
 

Between Lemmy versions v0.8.10 and v0.9.0, we did a major database rewrite, which helped to improve compilation time by around 30% (see below). In this post we are going to explain which methods were effective to speed up Rust compilation for Lemmy, and which werent.

Compilation time comparison

Here is a comparison of debug compilation times for Lemmy. All measurements were done in with Rust 1.47.0, on Manjaro Linux and an AMD Ryzen 5 2600 (6 cores, 12 threads). Results are taken as the average of 5 runs each.

v0.8.10 v0.9.0-rc.11 improvement
Clean build 195s 129s 34%
Incremental build 23s 17s 26%

Build Graph

The build graph and statistics can be generated with the following command, which will generate a file cargo-timing.html.

cargo +nightly build -Ztimings

In our experience, it is really the most useful tool in order to speed up compilation time. There are a few ways to use it:

  • The table at the bottom shows which crates took longest to compile. You can try disable unused features for slow crates, or remove those dependencies entirely. If your own crates are slow, split them up (see below).
  • In the bar graph near the top, you can mouse over each crate to see which other crate it has to wait for in order to start compilation. You can try to remove these dependencies, or features that you don't need.

Splitting code into workspaces

This is often tricky to do, but proved to be the most effective way to speed up compilation. At the same time, it helped to better organise our code into independent parts, which will make future maintenance work easier.

As a first step, it is enough to split the code into crates which depend on each other linearly, as this is relatively easy and already helps to speed up incremental builds (because only part of the project needs to be recompiled when something is changed).

In case you have a particular dependency which takes very long to build, you should take all code which does not depend on that dependency, and move it into a separate crate. Then both of them can be built in parallel, reducing the overall build time.

Later you can try to reorganise your code so that crates in your project can be compiled in parallel. You can see below how we did that in Lemmy:

Before:

After:

As you can see in the before screenshot, all Lemmy crates are compiled linearly, which takes longer. In the after screenshot, at least some of the database crates are compiled in parallel, which saves time on any computer with multiple CPU cores.

For more details on how to use cargo workspaces, have a look at the documentation

Disabling debug info

This is very easy to do, as it only requires putting the following into Cargo.toml:

[profile.dev]
debug = 0

The effect is that debug information isn't included in the binary, which makes the binary much smaller and thus speeds up the build (especially incremental builds). We never use a debugger in our development, so changing this doesn't have any negative effect at all for us. Note that stack traces for crashes still work fine without debug info.

Here it is in the documentation

Removing dependencies

This only had limited success, for the most part. We weren't willing to remove or replace any of our dependencies, because then we would have to remove features, or have a lot of extra work to reimplement things ourselves.

However, there is one specific dependency where we could improve compilation time by around 50 seconds. Refactoring the database allowed us to remove diesel's 64-colum-tables feature. This was especially effective because diesel only has a single crate, and as a result is compiled on a single thread. This resulted in a period of 40 seconds where one thread would compile diesel, while all other threads were idle. There is still room for improvement here, if diesel can be split into multiple, parallel crates.

Lemmy issue with more details

With actix we noticed that it includes a compression library by default, which is useless in our case because we use a reverse proxy. Thanks to @robjtede from the actix for making the necessary changes to allow removing that library. In the end the effect was limited however, because the library could be built very early and in parallel to other things, without blocking anything. It should help with compilation on devices with few CPU cores at least.

Issue in the actix-web repo

Other optimisations

cargo bloat was commonly recommended in order to find large functions, and split them up. But that didn't help at all in our case, probably because our project is quite large. It might be more useful for smaller projects with less code and less dependencies.

It was also suggested to reduce macro usage, but there wasn't much opportunity in our case because diesel uses a lot of macros. We removed a few derive statements that weren't needed, but without any noticable effect.

232
 
 

Apologies if this question isn't really appropriate for this community, but Rust and Kotlin are my two favorite programming languages, and currently, I use both for different projects. However, I'm curious as to if people here think Kotlin still has a place when Rust exists? I'm specifically speaking architecturally: disregarding existing legacy code or support, do you think in the future, the Rust platform should replace the Kotlin platforms (JVM, LLVM Native, Android, Web) for everything Kotlin can do, or do you think Kotlin can do some things better than Rust?

233
 
 

Haven't tried it yet but it looks super neat.

234
 
 

Development and project specifications are on their gitlab page: https://gitlab.com/robigalia

235
 
 

Considering introducing to Plume.

236
 
 

Genuinely serious since this is so much of a meme.

237
238
 
 

I'm looking to build something in Rust that requires being able to extract a variety of archive and compressed file formats, like various forms of compressed tar files, zip files, iso files, etc. The 7zip software suite is really good at both auto-detecting what format it's in and extracting almost anything you throw at it (it even dumps out the objects in Linux, Mac and Windows executables).

I was originally just thinking of including 7zip as a dependency and calling its command line tool from Rust so I can get it to do all the work, but is there a Rust library that is similarly versatile that I can use instead, or is 7zip actually my best option?

239
240
 
 

Flowgger is a fast, simple and lightweight data collector written in Rust.

Alternative to Fluentd and Logstash.

241
242
 
 

Tantivy 0.10.0 is released.

Tantivy is a search engine library inspired by Lucene. It is already fast.

I think it is fair to say this release does not contain any major changes, considering the amount of time since last release.

Life have been pretty busy, and a large amount of my tantivy time is spent answering emails/issues/messages nowadays. Fortunately, tantivy now has a lot of contributors that can help polish the project into a great search engine library.

Kudos to @hntd187, @petr-tik, @fdb-hiroshima, @kompass, @uvd, and @drusellers for the great work! Thanks also to all of the patreons : Colin, Florian, Frederik, Nate, Sanghyeon, Stephen and Zane!

Any kind of support -communication, code, patreon- really helps tantivy!

Here goes the changelog :

Tantivy 0.10.0

Tantivy 0.10.0 index format is compatible with the index format in 0.9.0.

  • Added an API to easily tweak or entirely replace the default score. See TopDocs::tweak_scoreand TopScore::custom_score (@pmasure l)

  • Added an ASCII folding filter (@drusellers)

  • Bugfix in query.count in presence of deletes (@pmasurel)

  • Added .explain(...) in Query and Weight to (@pmasurel)

  • Added an efficient way to delete_all_documents in IndexWriter (@petr-tik).

    All segments are simply removed.

Minor

  • Switched to Rust 2018 (@uvd)
  • Small simplification of the code. Calling .freq() or .doc() when .advance() has never been called on segment postings should panic from now on.
  • Tokens exceeding u16::max_value() - 4 chars are discarded silently instead o f panicking.
  • Fast fields are now preloaded when the SegmentReader is created.
  • IndexMeta is now public. (@hntd187)
  • IndexWriter add_document, delete_term. IndexWriter is Sync, making i t possible to use it with a Arc<RwLock<IndexWriter>>. add_document and delete_term can only require a read lock. (@pmasurel)
  • Introducing Opstamp as an expressive type alias for u64. (@petr-tik)
  • Stamper now relies on AtomicU64 on all platforms (@petr-tik)
  • Bugfix - Files get deleted slightly earlier
  • Compilation resources improved (@fdb-hiroshima)

How to update?

Your program should be usable as is.

Fast fields

Fast fields used to be accessed directly from the SegmentReader. The API changed, you are now required to acquire your fast field reader via the segment_reader.fast_fields(), and use one of the typed method:

  • .u64(), .i64() if your field is single-valued ;
  • .u64s(), .i64s() if your field is multi-valued ;
  • .bytes() if your field is bytes fast field.
243
244
9
The embedded Rust Book. (rust-embedded.github.io)
submitted 6 years ago by dessalines@lemmy.ml to c/rust@lemmy.ml
245
 
 

Written by me and gegy1000. We have implemented the following:

  • Physical memory manager (buddy allocator)
  • Virtual memory manager
  • Kernel heap (buddy allocator)
  • Serial (for logging)
  • PIC, interrupts (incl. IST)
  • PIT
  • PS/2 (busy being reworked), keyboard input
  • Snake game (runs on boot in kernel mode)
  • ACPI (through acpi crate, with which we are involved)

Currently in progress:

  • Userspace
  • PS/2 rewrite
  • System calls
246
247
 
 

Oh boy, here we go