16 ms·
Rust 1.24
- clarkmoody 9y agoIncremental compilation turned on by default :-)
- jolmg 9y agoHmm... when I read that, I got excited thinking it would be like Common Lisp's, where the idea is to incrementally compile in changes to a running program, to the effect of being able to see the effects without having to restart it. This just sounds like what Makefiles do, but at a sub-file/AST level.
- steveklabnik 9y agoIt's an overloaded term, it means both, basically. Your analogy to Makefiles is right in a big-picture sense. In the small, it's different, but you've got the big idea correct.
- eslaught 9y ago> If you’re a fan of str::find, which is used to find a given char inside of a &str, you’ll be happy to see this pull request: it’s now 10x faster! This is thanks to memchr. Wait, how is that safe? Aren't Rust strings UTF-8? Even if you search for a ASCII character, couldn't it conflict with the second byte of a different unicode codepoint?
- wolf550e 9y agoAn ASCII char would have its MSB 0 in UTF-8, and any byte in UTF-8 which is not a single ASCII char has its MSB as 1.
- stouset 9y agohttps://github.com/rust-lang/rust/pull/46735 https://github.com/rust-lang/rust/pull/46735 TL;DR, it's not a naive straight `memchr`. `memchr` will generate false positives, then they use knowledge of UTF-8 to weed out the false positives. The pathological case is worse, but the overwhelming majority of cases are better.
- Manishearth 9y agoSure, and the code deals with that case. https://github.com/rust-lang/rust/blob/5cf55165fae5c8538db5c00e252ad9ba42aaf246/src/libcore/str/pattern.rs#L314-L340 https://github.com/rust-lang/rust/blob/5cf55165fae5c8538db5c... This does mean you have some somewhat pathological cases, but they're relatively rare because most strings come from only a couple unicode blocks, so all bytes other than the first will be from a really small set. A further optimization could be to fall back to the original find code if we realize we're hitting a pathological case. (Also, FWIW, searching for an ASCII char can never cause this because of how UTF8's streaming property -- https://en.wikipedia.org/wiki/UTF-8#Description https://en.wikipedia.org/wiki/UTF-8#Description -- but given that we only search for the last byte, searching for a multibyte codepoint can lead to false positives with a shared last byte. We handle that.)
- Felk 9y agoIf I'm not wrong, UTF-8 continuation bytes always start with binary 10, where ASCII always starts with 0 and multi-byte starts start with either 11 (2 bytes), 111 (3 bytes) or 1111 (4 bytes)
- paulddraper 9y agoCorrect. This is what makes UTF-8 is "self-correcting", in that you can always find which code unit you are at for a code point.
- Manishearth 9y agoThat doesn't solve the problem of searching for multibyte character AB and finding multibyte character CB instead :) Or, searching for multibyte character ABB (like U+A041 YI SYLLABLE PA) and finding the first "B" instead of the second "B". Sadly there's no memchr for consecutive sequences of characters. memchr2/memchr3 let you search for multiple needles in the haystack, not a bigger needle.
- comex 9y agoThere’s memmem...
- burntsushi 9y agomemmem is substring search. You could use it for char search, but does memmem know about UTF-8? If, say, memmem uses memchr internally in a skip loop and it happens to look at the first byte in the UTF-8 encoded codepoint, then it is going to perform a lot worse in most cases involving the search of text that is in a language other than English (because it will wind up searching for a very common byte). Or maybe memmem does something else clever for shorter needles. Dunno. Best to benchmark it. But it's not an obvious win a priori.
- Manishearth 9y agoI do want to see if a 2/3/4-byte memchr can be written that uses the same bitmasking as regular memchr but extended to more bits (perhaps via SIMD). That would be pretty neat.
- masklinn 9y agoUTF8 streams are self-synchronizing: an ASCII byte starts with 0, a most-significant byte starts with 11 and a continuation byte starts with 10. You can memchr for the last byte (either 0xxxxxxx for only byte or 10xxxxxx), then in the latter case go backwards to the MSB to see if the entire codepoint matches.
- pixelbeat__ 9y agoYou can use strchr() for ascii, or strstr() otherwise. See utf8, searching section in http://www.pixelbeat.org/docs/utf8_programming.html http://www.pixelbeat.org/docs/utf8_programming.html
- kibwen 9y agoIncremental compilation! And it's only going to incremental-er from here, as the compiler learns how to cache more and more sorts of interim artifacts to avoid redundant work. Though I think the wording in the OP is a bit off: > Historically, the compiler has compiled your entire project, no matter how little you’ve changed the code. This isn't quite correct. When you change the code in a given library, it has historically recompiled that entire library, and all libraries that depend on that library. But the compiler has never recompiled any libraries that were deeper in the dependency chain: if you have crates foo and bar, and bar imports foo, and you change the code in bar, foo was not recompiled. Looking towards the future, I'm most excited about the prospect of using SIMD on stable Rust, which looks to be coming this year: https://github.com/rust-lang/rfcs/pull/2325 https://github.com/rust-lang/rfcs/pull/2325 EDIT: Also worth mentioning is that Rayon (an official Rust library providing easy data parallelism) just reached 1.0 today, which is an important milestone in Rust's march towards ecosystem stability: https://github.com/rayon-rs/rayon https://github.com/rayon-rs/rayon
- yazaddaruvala 9y agoHave there been any thoughts around making the compiler something akin to a stateful server with an embedded datastore for the caching rather than using the filesystem?
- steveklabnik 9y agoNot directly, but there's been some work on changing the compiler's interfaces to ones that would work with that model, in my understanding. It's not out of the realm of possibility.
- Nelkins 9y agoI think this is something that C# and VB.NET do.
- AceJohnny2 9y agoWhat would be the benefit of this approach over using the filesystem?
- talson 9y agoCan someone sell me on using rust over python? I am just gernerally curious as to the advantage beyond rust being compiled.
- walkingolof 9y agoThis may be a good start: http://lucumr.pocoo.org/2015/5/27/rust-for-pythonistas/ http://lucumr.pocoo.org/2015/5/27/rust-for-pythonistas/
- michaelchisari 9y agoPerformance is quite a bit higher for rust. And it's a much safer language by design (and forces the programmer to be as such). That said, development time in Python is much faster. Honestly, it depends on what you're building.
- Etzos 9y agoI'm curious what parts of Rust you think are safer than Python. Edit: The only big thing I can think of is the safety of compile-time type checking to ensure you won't end up with some kind of runtime error from mismatched types. Is there something I'm missing?
- michaelchisari 9y agoThat's a big one.
- smaddox 9y agoRust also enforces deep immutability by default, which makes resource sharing bugs much less common.
- lmm 9y agoWhen you work with the type system it checks a lot more than you check in Python. In Python you pass around untyped tuples and maps because defining classes won't gain you anything (and is surprisingly cumbersome and unpythonic), whereas in an ML-family language like Rust you use lightweight, fine-grained types to check that every function call is correct and you can refactor fearlessly. (I'd recommend using a language with garbage collection unless you really need to not though; OCaml is quite Rust-like but means you won't have to worry about the borrow checker)
- dhbradshaw 9y agoSatisfying to see rustfmt hitting stable, even if only in preview form.
- deadprogram 9y agoAgreed!
- deadprogram 9y agorustfmt looks very cool. I look forward to using that partcular feature.
- XR0CSWV3h3kZWg 9y agoIs rustfmt fast enough to reasonable be put on a save hook?
- steveklabnik 9y agoI went into one of my projects and did a `cargo fmt`, took 2.2 seconds. Dunno if that's within your tolerances or not. I personally have CI check it, rather than on save.
- wldcordeiro 9y agocommit or push hook is nice in my opinion. Seems like a middle ground to on save and in CI.
- XR0CSWV3h3kZWg 9y agoHmm I assume that cargo fmt does it on all the files, When I wrote a lot of go I had gofmt on the write hook of my editor. It was fast enough for single files that there was never a problem. 2.2 seconds sounds rough, but if that's for lots of files it's not too much of a worry.
- RX14 9y agoI know it's fairly pointless performance bashing but I just couldn't stop myself :) # In the crystal-lang/crystal repo $ find . -name '*.cr' -print0 | wc -l --files0-from=- | tail -n 1 252745 total $ time bin/crystal tool format Using compiled compiler at `.build/crystal' bin/crystal tool format 0.62s user 0.04s system 106% cpu 0.625 total and only 48ms to formal the longest file in crystal (the parser)! Performance makes little practical difference as long as formatting a single file is fast enough to be on-save, but it does highlight the very interesting way that the crystal formatter is implemented. I'm not sure how rustfmt is implemented but crystal's formatter parses the file into the AST, and then does a single visitor pass of the file, in order, with a lexer in tow. It then basically reconstructs the entire file from scratch using the data both from the AST and the lexer (the AST visitor pass and lexer position have to be kept in sync). And surprisingly enough, this doesn't even make the formatter "too strict" in the way that it wipes out all existing style information as one would expect. It's a really cool - if a little messy - tool and one of I think my favorite parts of crystal (it doesn't have any config options either).
- deleted 9y ago[deleted]
- fafhrd91 9y agotokio-minihttp is 1 in plaintext benchmark in TechEmpower Web frameworks benchmark https://www.techempower.com/benchmarks/#section=data-r15&hw=ph&test=plaintext https://www.techempower.com/benchmarks/#section=data-r15&hw=...
- fafhrd91 9y agohyper is 6 and actix is 7 https://github.com/actix/actix-web https://github.com/actix/actix-web Rust is represented well!
- jrhurst 9y agoI tried Actix a while back and it was very intimidating compared to some other frameworks. I'd like to jump back into it at some point, but right now for my prototype I got lazy and went with Rocket.rs. Any suggestions of Opensource projects that use Actix?
- fafhrd91 9y agoyou should check it again :) actix-web now has user guide https://actix.github.io/actix-web/guide/ https://actix.github.io/actix-web/guide/ here is irc bot (wip) https://github.com/DoumanAsh/roseline.rs https://github.com/DoumanAsh/roseline.rs
- todd_wanna_code 9y agoIs there a guide just for using the actix framework that explains what are actors, how they are different from other abstractions and the pros and cons?
- fafhrd91 9y agoThere is no guide for actix but I am planing to add one
- 9y ago
- deleted 9y ago[deleted]
- dsymonds 9y agoGood to see rustfmt arrive. Sad that it is configurable, though. The biggest benefit of its predecessors such as gofmt is that they are not configurable, leading to a much more uniform formatting style and avoiding endless discussions about whitespace layout.
- steveklabnik 9y agoYeah, I'm not psyched about it either, but that ship has sailed. The defaults are what's considered the "official" style; we expect the vast majority of people to use it. Defaults are powerful.
- pcwalton 9y agoIf rustfmt were not configurable, it would get a lot less use. Rust has been around for quite some time now, and there's a lot of code out there. We can't force anybody to run rustfmt, and if they don't like the results, they won't use it. It's not a choice between different code styles and a single code style; it's a choice between different code styles with a tool to keep things tidy and different code styles with a tool nobody uses. Things were different for Go for a variety of historical reasons, one important reason being that gofmt existed early on. To take a concrete example, adopting gofmt's choice to not have a line length limit would have been a nonstarter, because lots of code out there uses long expressions manually wrapped to be readable. A lot of the work in rustfmt has gone into playing nicely with community conventions like these.
- coffeeacc 9y agoAgreed - I am an example. I had vim format my rust code on save, but there was one single bit of formatting which drove me nuts, so I turned the plugin off.
- dullgiulio 9y agogofmt choice of not breaking lines is due to the fact that new lines in Go mean an implicit semicolon unless there is a comma or another continuation. To break lines, the formatter would have to refactor code, which is not desiderable.
- xstartup 9y agoIs Helix still best Ruby-Rust way?
- nikkettt 9y agoI recently rewrote a few small c scripts in Rust, (mostly to try the language features), the experience was really good. I don't think I will ever start a new project in C again.