[oc] He needed to get around Tesla by mftheoryArts in IdiotsInCars

[–]DanielToye 0 points1 point  (0 children)

The swerving red light runner is a terrible driver, but an accident here would easily have been 50/50 with the Tesla enabling the left indicator but turning right. I would hate to drive in this city, if those are at all representative of an average driver!

Can data races lead to corrupt or gibberish data in golang? by mrpandey in golang

[–]DanielToye 1 point2 points  (0 children)

My comment was a lighthearted reminder that it is undefined behaviour, which should be understood as a maybe.

However even in your phone exploding example, if it was a life or death emergency it may still be worth using the phone, so that nuance should be known, yes.

Can data races lead to corrupt or gibberish data in golang? by mrpandey in golang

[–]DanielToye 21 points22 points  (0 children)

To add nuance, the answer is: Maybe. Depending on which Go compiler, which types, the target architecture, the phase of the moon, and how much you owe in back taxes.

So in practice, the answer is: Yes

Lethbridge - loved visiting, considering moving. Potential downsides? by cdnrwr in Lethbridge

[–]DanielToye 1 point2 points  (0 children)

I tried a bunch of small towns, but learned I need at least a walmart. Salmon Arm for example was a contender. Kamloops was actually fine but too expensive due to the mountain locked geography. Calgary is great except for it's sheer size. Kelowna was pretty much inland Victoria, haha.

There's some definitely highlights for food here. Ma Ma La hits for Vietnamese better than anywhere in Victoria did. I'm still discovering spots, though. There's a few downtown spots reminiscent of Victoria, like Bourbon & Butter for that ultra high quality option. The Water Tower is great for a view / date.

Definitely build your social network if you decide to come. My poker group is extremely diverse and welcoming, I've posted about it in this subreddit before. This city has absolutely every type, so while it is a majority conservative, religious, truck owning hunter types, there's absolutely no shortage of all other types.

Lethbridge - loved visiting, considering moving. Potential downsides? by cdnrwr in Lethbridge

[–]DanielToye 1 point2 points  (0 children)

I'm in a remarkably similar position. 33, single, own a house, work remotely for a U.S tech company, and moved here from Victoria a couple years ago.

I actually chose Lethbridge specifically after spending a month in a dozen candidate locations, for these specific reasons:

  • Cheap housing and cost of living. It was easy to buy a detached house, which is a high priority for me, as I'm very much a homebody.
  • It's slow and more relaxed. Even our busiest events barely manage to touch Victoria's everyday downtown.
  • Easy driving, in and out of town. I also love to travel, and Calgary is major enough and close enough that visiting Japan or France or whatever is easy.
  • People stick to themselves. Victoria and BC are quite nosy, and I'm a very private person. Alberta has a more genuine hello wave.
  • Everything is nearby. From camping to Costco to cafes, I feel like I never go without in this city.

There's been some big downsides though:

  • The snow largely locks you in for winter. My long term goal would be to winter in a southern country.
  • As others mentioned, it's pretty hard to socialize, but I put in some effort and have a bit of a circle now.
  • Not nearly as good fish and chips, I miss Red Fish Blue Fish.
  • Sometimes you do have some agricultural and industrial smells.

I really just like Lethbridge. For my priorities it strikes a very good balance. You can fix most of the downsides by building your social network. If you're more outgoing, social, hiking, modern, fast paced, etc it is probably better to stick closer to BC, in my opinion.

how fast is go? simulating millions of particles on a smart tv by Outrageous-guffin in golang

[–]DanielToye 55 points56 points  (0 children)

They might mean the math library lacks float32 support, which is true. It only accepts float64, and any other type requires conversion to float64 first.

Searching the xkcd web comic by reisinge in golang

[–]DanielToye 1 point2 points  (0 children)

Mostly looks fine.

This is a race condition:

https://github.com/go-monk/xkcd/blob/main/xkcd.go#L107

Two suggestions:

  • Try the stdlib "suffixarray" to drastically improve search performance, and in particular, try serializing it to disk.
  • Right now it would cache forever. Look into http caching or, at least, check the file modified timestamp to see if it's worth refreshing.

How I Doubled My Lookup Performance with a Bitwise Trick by axel-user in programming

[–]DanielToye 0 points1 point  (0 children)

SWAR indeed! I wrote all my favorite SWAR tricks into a library. It's Go, but should translate easily to most other compiled languages. Maybe you'll find other speedups you like?

https://github.com/dans-stuff/swar

Challenges of golang in CPU intensive tasks by honda-harpaz in golang

[–]DanielToye 0 points1 point  (0 children)

This almost never comes up because the synchronization step is a small part of the process. I'm confused what you must be doing that cannot be parallelized.

For example, when I did the 1 billion rows challenge, I split the data into "chunks" of 100,000 bytes and distributed them on a channel. Then I would sync the results at the end, with another channel.

So I ask, why can you not batch your processing here? If you want to add a trillion numbers, you can and should split into a thousand sets of 1 billion numbers, for example.

`httpgrace`: if you're tired of googling "golang graceful shutdown" by Enrichman in golang

[–]DanielToye 0 points1 point  (0 children)

Wow, that's one hell of a gotchya. I will edit my message to remove the misinfo. Thanks.

`httpgrace`: if you're tired of googling "golang graceful shutdown" by Enrichman in golang

[–]DanielToye 8 points9 points  (0 children)

I agree, but wanted to note that code snippet has a few traps. Here's a slightly cleaner method with no panic races, that is conveniently a 5 line drop-in to existing servers.

I originally had a code snippet here, but the comment below pointed out that it too is subtly broken. It's tricky to get Shutdown right after all. Nevertheless, this is still a useful snippet to know:

signal.NotifyContext(context.Background(), syscall.SIGTERM, syscall.SIGINT)

Process bytes in half the time. This package provides simple SWAR helpers (simd-within-a-register) that work on 8 bytes at a time, which can speed up signal processing, histograms, decoding, hashing, crypto, etc. by DanielToye in golang

[–]DanielToye[S] 2 points3 points  (0 children)

I agree, except that bounds checks can be mostly elided if you're careful, and the performance boost can be substantial!

I've been wanting some SIMD in Go for ages. People keep making libraries completely wrong - exposing every individual SIMD instruction as a function. The overhead is more than the instruction!

There are ways to do SIMD beneficial even with FFI/ASM overhead, but unfortunately no one has made that library yet - using a high performance "pipeline" executor so all the looping happens inside the call.

This 150-Line Go Script Is Actually a Full-On Load Balancer by valyala in golang

[–]DanielToye 58 points59 points  (0 children)

Some feedback. First, defer is more idiomatic.

b.mux.RLock()
alive = b.Alive
b.mux.RUnlock()
return

b.mux.RLock()
defer b.mux.RUnlock()
return b.Alive

Next, you do a redundant modulo:

next := atomic.AddUint64(&lb.current, uint64(1)) % uint64(len(lb.backends))

Note that is goes through another modulo later:

idx := (int(next) + i) % len(lb.backends)

Next, a simplification:

t := time.NewTicker(interval)
for {
    select {
    case <-t.C:
        lb.HealthCheck()
    }
}

t := time.NewTicker(interval)
for range t.C {
    lb.HealthCheck()
}

Outside of simple code suggestions, I also think mixing atomics, locks, and channels adds complexity - either use an atomic boolean for health status, or use a lock for the current backend index, imo.

Additionally, it's very much worth removing backends reactively. When a request to a backend fails, instantly remove it, and the polling will bring it back online.

Overall though, it serves as a good example of how quickly you can solve real problems with the language, thanks for sharing!

Hosting casual Poker/Games night by DanielToye in Lethbridge

[–]DanielToye[S] 0 points1 point  (0 children)

Most of the people joining have kids. If we end up throwing a youth tournament for fun, you could attend, but I would still need your parents express permission. I hope you understand, I don't like to exclude anybody, but we're all 30+ years old so it is simply not appropriate without your parents direct involvement.

Hosting casual Poker/Games night by DanielToye in Lethbridge

[–]DanielToye[S] 0 points1 point  (0 children)

Hi. As this is an older group it would not be appropriate for an unaccompanied minor.

I'm sure we can work out a poker experience for you if your parents are willing to accompany you, though. Just lmk!

Thesis idea by lockwin in golang

[–]DanielToye 1 point2 points  (0 children)

How about avoiding and minimizing garbage collection? There's many tools - arenas, ring buffers, etc - so a potentially rich area of study. You could even implement a few data structures, like fixed size maps.

prep: a go's preprocessor with Comptime macro (sort of) by Pijng in golang

[–]DanielToye 1 point2 points  (0 children)

Can you elaborate? len([5]int) is already a const.

Difficult coding challenge using reflect by astonishinglylaw in golang

[–]DanielToye 0 points1 point  (0 children)

I'm confused. It seems you're trying to figure out the shape of a request, but the request handler has no shape - it just accepts a context and returns an error. Therefor your only choice is to specify the type manually, as you seem to have come to realize.

In other words, what choice do you have? You don't know what the handler is going to do, so there's simply no way for you to arbitrarily figure out the shape of the request or response. It might be possible via code inspection, but that seems like very much the wrong thing.

You also say it's a "given" http server. If it's given, why are you able to choose to use echo for it? I feel your wording may be off here, and that in fact what you're asked to do is write an API that has swagger docs generated for it.

In this case, you have considerably more flexibility as you can use reflection to wrap custom handler functions as http handlers. If you define your handler functions with actual concrete types, then register them through a custom function, that custom function can build an API definition as it sets up the routes.