Y
HN Search
Hacker News Search
new
|
comments
|
top
|
jobs
pkolaczk
searching PlanetScale…
1.
▲
2.
▲
3.
▲
4.
▲
5.
▲
6.
▲
18 ms
·
211.
▲
by
pkolaczk
3y ago
No, this still allocates a new string array per each line.split call. It's not really a problem with variables. The variables are likely on the stack anyways, but they only store pointers to data on the heap. If you call any function t
212.
▲
by
pkolaczk
3y ago
If you want to reuse an object to avoid allocation, you better not have a reference to that object from somewhere else. In JS AFAIK there is no way to detect such situation automatically.
213.
▲
by
pkolaczk
3y ago
> Go might’ve been a better option if you were going for a “modern” concurrent language, but whatever works! Go doesn't embed in other runtimes as nicely as Rust, nor it cannot call foreign code (including even C) as efficiently as
214.
▲
by
pkolaczk
3y ago
That approach may work in short term but in long term you'd likely end up with unreadable and brittle code that is often still not as fast as it would be after the rewrite. You'd introduce additional complexity into your product t
215.
▲
by
pkolaczk
3y ago
1. Java does not allow to implement new interfaces for classes without modifying their signature - much more limiting than Rusts foreign trait rule. You cannot make a foreign class implement your new interface. 2. Java does not allow to cre
216.
▲
by
pkolaczk
3y ago
Elegance of code is subjective and developer productivity is more a trait of a developer than a language (which means it is inherently subjective, e.g. in my case Python is among the languages I was least productive in; I find myself much m
217.
▲
by
pkolaczk
3y ago
> Horror! To me, the acceptable slowdown is exactly zero. If you care about single % of performance, why are you using Python in the first place? You're likely losing 100x to more performant languages already.
218.
▲
by
pkolaczk
3y ago
This is the way how Java iterators work. And having worked with them for many years I must say - please don't go that route. Having separate hasNext/next methods is terrible for implementers of the iterator. The problem arises wh
219.
▲
by
pkolaczk
3y ago
Keeping complexity out of the language does not remove the complexity. It moves it into the programs. MIPS assembly is a very simple language with specs fitting on 10 pages. Yet you probably wouldn't want to write a web application in
220.
▲
by
pkolaczk
3y ago
Why slap additional charge on top if it is ICE? Some ICE cars emit less CO2 over their lifetime than EVs, especially when driven only in city, on short distances, in which case the lower CO2 emissions from driving don't offset much hig
221.
▲
by
pkolaczk
3y ago
If one could only buy minivans these times. If you're in Europe, you're out of luck. There is an outdated Sharan/Alhambra with tech from 2015 and tiny TSI engine with whopping 14s 0-100 km/h acceleration. And a bit more
222.
▲
by
pkolaczk
3y ago
Well, not everybody drives alone. Moving one person in a car emits comparable amount of CO2 as a person going by foot and moving only two people by car emits less CO2 than moving those two people on foot. We should discourage driving alone,
223.
▲
by
pkolaczk
3y ago
That's unfair. If one person drives 1000 km annually in a big SUV and another person drives 100000 km annually in a small and efficient hybrid sedan, then obviously the latter emits more CO2. And if hypothetically they walked the same
224.
▲
by
pkolaczk
3y ago
Rust compiler warns about ignoring a result of functions annotated with #[must_use]. This is optional because if a function has no side effects, then ignoring its return value is not a problem and shouldn't be warned about.
225.
▲
by
pkolaczk
3y ago
Why is it such a problem? Can't debuggers use `Debug` trait if defined? Or do they already?
226.
▲
by
pkolaczk
3y ago
But this approach already works with multithreaded runner and there are no data races or consistency problems. They would be caught by rust borrow checker anyways.
227.
▲
by
pkolaczk
3y ago
The borrow checker does catch those issues. But it it does not do whole-program analysis. It analyzes code locally, by looking at signatures of functions being called. And also being forced to read distant code to understand if given snip
228.
▲
by
pkolaczk
3y ago
> As I mentioned else thread, if you do not care about parallelism you can pin your threads and use SCHED_FIFO for scheduling and then you do not need any synchronization. I don't think it is a universal solution. What if I am inter
229.
▲
by
pkolaczk
3y ago
But that's not synchronization between two concurrent things. I can still reason about queue being full in a sequential way. select! { _ = channel.readable(), if queue.has_free_space() => read(&mut queue), _ =
230.
▲
by
pkolaczk
3y ago
> Any normal function call can do these things. A normal function cannot switch threads. foo(); // executed on thread 1 doSomeIO().await; bar(); // possibly continued on thread 2 Now if foo() does s
231.
▲
by
pkolaczk
3y ago
> wouldn't be any different than someone adding an "await foo()" right now It would. `.await` works only inside `async` context. So if the method wasn't async at the top level, then adding `.await` somewhere down the
232.
▲
by
pkolaczk
3y ago
Well, not really, because async/await guarantees I don't have to deal with the problem of producer adding data at the same time as consumer is removing the data in this case. In a proper SPSC queue some degree of synchronization i
233.
▲
by
pkolaczk
3y ago
Point taken. What about this pattern (pseudo code, obviously it would require e.g. adding some code for tracking how much data there is in the buffer or breaking the loop on EOF, but it illustrates the point): mut buffer: &[u8] = .
234.
▲
by
pkolaczk
3y ago
> We still need them if we have multiple coroutines using a shared resource across multiple yield points. We still need them if we have multiple parallel tasks (coroutines spawned non-locally) using a shared resource across multiple yi
235.
▲
by
pkolaczk
3y ago
I don't think so, it would only mislead and hide what's really going on. Creating a future in Rust does not have any side effects like running the future in background. This is not JS. Creating a future is just creating an objec
236.
▲
by
pkolaczk
3y ago
> Only if you know that foo is an async function. You can't tell by the function call itelf. That's fair point, but traditionally you don't use blocking functions in async contexts at all. It is fairly easy to lint for by
237.
▲
by
pkolaczk
3y ago
You're talking about particular JS implementation problems, not general async/await problems. > In Go you have to explicitly state that a function is to run in the background via "go fn(...)". In Rust you have to exp
238.
▲
by
pkolaczk
3y ago
async/await allows to do concurrency without the need for explicit synchronization to shared data structures. E.g. I can do: loop { select! { _ = src_channel.readable() => src_channel.read(&mut buffer),
239.
▲
by
pkolaczk
3y ago
It's pointer bumping in optimistic case. Eventually it runs out of current slab and... then there is some more work to do. And also those page faults are actually quite likely as it gives you memory that hasn't been used recently.
240.
▲
by
pkolaczk
3y ago
Card marking does not identify pointers directly, but only identifies parts of the heap that may contain pointers to the new gen. So those parts still need to be scanned. Surely, it is way less work than scanning the whole heap, but still n
More ›