Better HN
topnewbestaskshowjobs
Log inSign up

codedokode

9,867 karma · joined Aug 20, 2015 (11y ago) · 5,528 submissions

PHP developer from Russia.
Submissions

comment 6mo ago · link · parent

How it works in Russia, if your corporate VPN is blocked by mistake, you can just submit the application to whitelist it, providing all the necessary documentation (we have pretty advanced e-government system so you can submit it online), and with high probability it would be accepted. If your VPN gets accidentally blocked again, all you need is to write to an on-duty officer and it will be unblocked.

comment 6mo ago · link · parent

If you feel that parents are treated unfairly, the solution is to impose a tax on people without children and use it to pay the salary for raising kids. I think everybody agrees that monetary support is much better than verbal and moral support.

comment 6mo ago · link · parent

I think it was a bad idea to put cryptographic APIs or VPN in the kernel. If userspace is too slow for this, you should either reduce context switch overhead, or create special kind of processes, which are isolated, but quick to switch into. They are repeating Windows mistakes.

comment 6mo ago · link · parent

Maybe, but why normal people without children need to experience inconvenience, Internet restrictions and verifications just because there are a minority of negligent parents? Children are parents responsibility. Instead of banning adult sites, is not it better to ban families with children from Internet? Make some family-friendly Internet and let them all go there and not bother normal people.

comment 6mo ago · link · parent

I think, the best way to keep children from dangerous content is large fines for parents, for example, $4000 for every adult video their child was traumatized by due to their negligence. 50% of the fine is shared with the person who reported the violation (including site operators). After all being a parent is a responsibility.

Such law would not cause inconvenience to normal Internet users without children, would provide additional source of income for vigilant people and underpaid school staff, and would result in much higher degree of compliance. Why you guys don't elect people like me.

comment 6mo ago · link · parent

The callbacks should be just hidden from programmer, that's what async/await are for.

comment 6mo ago · link · parent

As I understand, "green threads" are also expensive, for example you either need to allocate a large stack for each "thread", or hook stack allocation to grow the stack dynamically (like Go does), and if you grow the stack, you might have to move it and cannot have pointers to stack objects.

comment 6mo ago · link · parent

This is not always available. What smartphones "serve well out of the box", meaning zero telemetry, root privileges, open source, not requiring an account in a foreign country (and not spamming notifications about this), and working? Google Pixel requires time to fix, despite costing like 3-4 ordinary smartphones.

The same probably can be said about laptops. Linux is great but buggy, and proprietary OSes do not pass the requirements.

comment 6mo ago · link · parent

Microsoft doesn't allow its users even to reboot the computer without permission?

comment 6mo ago · link · parent

Linux has lot of bugs and issues, but they are not caused by intention to make users' life worse.

comment 6mo ago · link · parent

It's interesting that OpenAI promised to make AI accessible for everyone, but China actually did it.

comment 6mo ago · link · parent

Not everyone needs 3D models to be fair.

comment 6mo ago · link · parent

Why 18-20 are isolated from 21+? Aren't they all adult or in some countries children develop slower?

comment 6mo ago · link · parent

No, it is because citizen allow treating them like this.

comment 6mo ago · link · parent

I didn't try, but loop contains a branch so there could be misprediction, which doesn't happen with unrolled loop. Also, instruction level parallelism applies to unrolled code as well.

comment 6mo ago · link · parent

> I was a bit confused by the if-else chains you have e.g. on line 111 where it looks like you could just use the else branch for every case?

The point of "ifs" there is to replace a variable "size" with a constant like 8, 16 so that the compiler can hardcode it in the code and maybe make it more efficient (for example, instead of counting the iterations the compiler can just repeat the instruction 8 times when iteration count is 8). I expect that the compiler would generate customized "linear_search" function versions instead of using generic version with unknown number of iterations. You can see the example in godbolt assembly code at line 825, where the compiler unrolled a loop for "linear_search" function with size = 8 - there is no loop, just 8 comparisons.

> As for the branch prediction, I would think most of the branches would be predicted correctly because usually you'll have runs of "not x" before each "is x". Switching between many loops of course hurts the prediction.

I don't think so. In binary search there is no predictable pattern, so the predictor would miss in 50% of cases. And in linear search there is a guaranteed miss in the last iteration.

> You could circumvent the counter issue by pinning to a specific core,

I think I'll try this in future.

> but I find I have to write some code yourself

I can write it myself, but it would take 20-30 minutes including time to find and read the docs for functions while for LLM it takes less than a minute. But anyway I have to edit the result a lot, for example LLM "forgot" that you need to use the result of the search to prevent compiler from throwing the code away. Also, free version of ChatGPT became much dumber couple of months ago.

comment 6mo ago · link · parent

I think the problem is with branches misprediction. Binary and linear searches use a lot of unpredictable branches that ruin performance. No-branch versions of search work faster. I wrote the details here: https://news.ycombinator.com/item?id=47983102

comment 6mo ago · link · parent

I often benchmark my DIY data structures, as well as check the assembly on godbolt. I think I wrote the code using ML model (they save lot of time), and then fixed the issues and extended it myself. I have the code here: https://pastebin.com/GzY4HMsZ

I do the search multiple (thousands) times and calculate total time spent, so the timer is called only 2 times. I search across the same array, but for the different number each time. So the array should be completely within L1 cache. It's also important to use the result of the search otherwise the compiler simply omits the code.

I use clock_gettime() which takes on order of 1us. Timestamp counter (which is faster) is not available for me because every CPU core has its own counter and they show different values, so Linux refuses to use it. First core is 600 ms ahead of other cores. How in 2025 we cannot make a boring counter amazes me. Or, maybe this is intentional to prevent using cheaper consumer hardware for professional purposes.

Here are some numbers:

Array size 8, 200 000 iterations, time ns/seach: linear 8 ns, linear no-branch <1 ns (I wonder if it is an error), binary 11 ns, binary no-branch 7 ns.

Array size 128, 100 000 iterations, time: linear 34 ns, linear no-branch 22 ns, binary 35 ns, binary no-branch 16 ns.

As you can see, the branches is what ruins the performance here. Every time the CPU mis-predicts a branch, it wastes several cycles.

Looking through disassembly on godbolt, the compiler inlined and vectorized the measurement loop for no-branch code, which might explain the numbers. The SIMD assembly is hard to read and I don't quite understand what it does: https://godbolt.org/z/dofKnT3W3

I'll be happy to read if you point me at any mistakes in my benchmark. If you want to compile the code, I used gcc with "-O3" and maybe with "-march=native".

comment 6mo ago · link · parent

I did little experiments with search in small arrays (16-32 items) and binary search is one of the worst methods because it requires lot of branches. The fastest method for small arrays was linear branchless search (you walk over all elements without breaking out of the loop. For example, if you want to know whether the array contains a number, you logically OR the checks for all items). I didn't use SIMD though, but the branches are very expensive for small arrays and simply checking all elements without branching is faster.

comment 6mo ago · link · parent

Internet-connected cars are a national security issue when manufacturers are from one country (A) and consumer is in another country (B). For example, the President of country A might wake up in a bad mood and order to disable all A-manufactured cars in B until they reconsider the trade deal. Or, he might order to collect geolocation, plugged for charging smartphone data, audio and video recordings from cars in B belonging to military personnel.

Smart cars can record street views, location of WiFi access points and GSM towers, and this data is useful for guiding missiles and drones when GPS is being jammed.

And how can we deal with this? Inspections on import? Country-level DPI to block data exfiltration? But DPI is not perfect because there are obfuscation and VPNs. And today we have Starlinks as well, which are difficult to block. Except from banning foreign smart cars altogether, there seems to be no simple solution. Or maybe oblige the manufacturer to use local computer boards and software when importing cars?

comment 6mo ago · link · parent

> Once real work flows through a SQLite-backed app, you need a queue. The usual answer is “add Redis + Celery.”

Are they joking? SQLite is usually used for single-process (mutliple threads) applications. The proper way to communicate between threads/processes is a ring buffer, where you allocate structs (allocation typically is incrementing a pointer), and futex/eventfd for notifications (+ some spinlocking to avoid going to kernel when the tasks arrive quickly). Why do you need redis for that? If you need persistent tasks, then you can store them in the table, and still use futex for notifications. This polling is inefficient and they should not make it a library which will cause other lazy developers add it to their app.

> honker polls SQLite’s PRAGMA data_version every millisecond. That’s a monotonic counter SQLite increments on every commit from any connection, journal mode, or process — a ~3 µs read for a precise wake signal

That's 3 ms per second = 0.3% CPU time wasted for every waiting thread.

Like Electron, this feels like written by a web developer and not a real programmer.

comment 6mo ago · link · parent

> But as long as it can be turned off I don't see why this is a problem.

That immediately makes you stand out, and sites will start breaking, like now some sites (that do not do any 3D graphics) break without WebGL.

> web is the world's most successful application platform.

Also one of the ugliest and poorly designed in my opinion.

comment 6mo ago · link · parent

Protocols like HTTP or formats like HTML were initially made to be machine-readable. You humans make your site machine-readable, publish on the internet and then get unhappy when machines start actually reading it.

Anyway, just put a captcha or require a cryptocurrency payment if you are unhappy with bots, but several people unhappy about scraping are less important than billion people unhappy about tracking their activity.

comment 6mo ago · link · parent

Yes, how sovereign national browsers (not depending on US companies and not sending data to US) can be be developed in this situation?

comment 6mo ago · link · parent

I am against this.

1) This will be a new source of fingerprinting information and this is difficult to fake to fool fingerprinting scripts, so it can be abused for "device verification". There should be no ability to "verify" a browser, and anyone should be able to emulate any browser. This is the most important point, I thought Google people are smart enough to see it.

2) LLMs use lot of memory and CPU time, for many users they would slow down their system significantly, and given current RAM prices, upgrades are very expensive. If the website relies on local model, it would work slow on cheap devices.

3) The API seems to be tailored for specific LLM like OpenAI.

4) This can be used to push competitors who do not have an AI model from the browser market - the sites would break because they will be made with expectation of having Google Gemini model and would not work with other models. For example, the sites would break in national browsers not having an AI model. There should be no "first-class" and "second-class" browsers.

The explainer claims that this would allow the user to process the data locally without sending it anywhere. But why does Google Gemini local model have "Prohobited Use Policy" then? Why should they bother about prompts and responses they never learn about?

While offline LLM access seems like a good idea, the website could use WebGPU for this without building LLM into the browser (or they could improve WebGPU for better handling ML models). Or everyone should use the same, open source, LLM.

comment 6mo ago · link · parent

This should apply not only to phones. Every device with CPU and programmable memory should allow user to reprogram it. However, the user may waive this right for purpose of theft protection.

comment 7mo ago · link · parent

Oh come on. Look what happened to Russian enterpreneur, Pavel Durov in France, and what happened to Julian Assange and to Edward Snowden. It's the same thing just wrapped in different colored package. You don't cooperate with the government, you have some suffering.

comment 7mo ago · link · parent

Maybe we could use a subset of SVG or PDF?
1
232425
185