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 4y ago · link · parent

These numbers seem completely wrong to me. You cannot add RSS, you should add PSS (proportional set size) and SWAP PSS to obtain true numbers. PSS values allow to account shared memory properly.

Here are the results that I got from my Linux system. I excluded all user-visible applications (like Firefox, terminal, ssh or text editor) and added up what was remanining. This includes systemd, system services like udevd, Gnome, user services like pulseaudio. Total memory consumption is 730 Megabytes (RAM + SWAP added).

I think the reasons for such high memory consumption are that Gnome shell is written in Javascript (gnome-shell alone uses 200 Mb) and there are many small daemons: for example, NTFS daemon uses 30 Mb, Xwayland uses 45 Mb, IME daemons use around 55 Mb and so on. Most daemons use somewhere around 5-15 Mb but there are so many of them that the result is this big.

For comparison, Firefox processes use somewhere around 1.2 Gb, Skype (Electron-based) uses 600 Mb, and desktop Telegram uses 600 Mb as well despite being written in C++.

If you wish to try this on your system, you can use this Python script: [1]. Don't forget to edit `get_group()` method to exclude user-visible applications (or close them). You need to run the script as root because otherwise you will be able to read only your own `smaps_rollup` files. The script also saves detailed stats in CSV format into /tmp/ram.csv.

If you don't want to use my script you can use htop and enable PSS and SWAP columns there (and you can remove useless SHR/RES).

[1] https://gist.github.com/codedokode/ddaedf4ae44cbfa16ca44dde6...

comment 4y ago · link · parent

SHR is not "shared" size, it is "potentially shareable size". Process might have 100 Mb of SHR and none of them actually shared.

You should use PSS which accounts for shared memory pages (by dividing their size across all processes).

comment 4y ago · link · parent

You are right. RSS values cannot be added. Imagine if there are 3 processes, each use 100 Mb of shared memory and 100 Mb of private. Summing the RSS we will get 200 + 200 + 200 = 600 Mb, however the true memory consumption is 100 (shared) + 100 + 100 + 100 = 400 Mb.

To count the memory properly, you should divide size of shared segments by number of processes using it. This is how PSS in Linux is implemented. You can safely add PSS values of different processes. If you have swap, you should also sum swap usage by processes.

As I understand, you can reliably count memory usage only in Linux because other OSes like Windows or Mac do not provide PSS in their Task Managers. Windows Task Manager at least has a documentation that describes what "memory" column means, and I failed to find such documentation for Mac, so we can safely assume that it displays random numbers remotely related to memory usage.

comment 4y ago · link · parent

And a kid phone allows to stay in touch with friends (those approved by parents) without exposing a child to any risks.

comment 4y ago · link · parent

Some kids can find a way to buy alcohol or cigarettes, but it doesn't mean that we should allow that for everyone. Adult phone should be discovered and confiscated by teachers or police if they see it.

comment 4y ago · link · parent

> but what is the age bracket you are using to define a child?

At least 18, or more if local government considers it reasonable to raise the age.

> Are they not permitted to do some research or reach out to supportive online communities?

They are permitted as long as they use only compliant sites. Talking to random strangers about this is not a good idea.

comment 4y ago · link · parent

You can say the same thing about alcohol or cigarettes. Obviously, kids can find a way to buy them illegally but it doesn't mean that we should allow that.

I propose to make it illegal to help kids to obtain access to adult Internet the same way as it is illegal to help them to buy alcohol.

comment 4y ago · link · parent

If UK government really cared about children, and not about surveillance and censorship, they would solve the problem another way.

The only way protect children online is to ban them from Internet. Children should not have access to normal laptops and smartphones, instead they should use "kid phones". Such phones would allow children to communicate only with people approved by parents or teachers and visit only approved sites. This way they will enjoy perfect safety which this Bill fails to provide.

Every site which wants to become approved, must fulfill all the requirements from the Bill and indicate this with a HTTP header. Kid phones and laptops should allow only to visit such compliant sites.

Kid-oriented phones and laptops must be visually distinctive: for example, have a shape of a cute animal. In this case teachers, parents or police will be able to instantly spot and confiscate illegal devices.

This is a win-win plan: kids would be safe and adults would be safe from government overreach. Obviously no government will agree to such plan.

comment 4y ago · link · parent

You (probably) cannot call it a "purchase" then.

comment 4y ago · link · parent

Why should we care about 99% of people? They are people who upload all their personal data to social networks agreeing to "we can do whatever we want" terms, they pay with a card, use Apple's and Microsoft's spyware (which marketing people call "telemetry") ridden operating systems, and install Chrome that sends a signal to Google every time they open a new tab and sends data about every form on every website they visit (which Google developers call "crowdsourcing" in the code [1]).

Make a customizable and privacy-respecting search for us, power users.

Also, I have noticed that Firefox internal search works good for sites you had visited. So when I want to visit a page I have seen earlier, I can go straight to it skipping Google.

Also, you can click on any search box and add it with a prefix, so that you can search MDN or Wikipedia directly, again, without informing Google.

[1] https://source.chromium.org/chromium/chromium/src/+/main:com...

comment 4y ago · link · parent

There are many tasks that do not require much intellect. For example, "here is a web store design mockup I have drawn. Generate the code for it. Integrate it with payment and delivery services". Today you need to hire developers, testers and other people. What if such trivial tasks could be performed by a neural network?

Another example is phone support. AI is already being used there, for example, in some banks (in Russia) you are first greeted by a robot if you call, and only if it cannot answer your question it will let you talk to the human.

comment 4y ago · link · parent

Looks interesting. Here is what I would change:

- increase screen size to at least 15.5" because small screen is unusable for programming and for browsing modern websites with large font size and large pictures

- use IPS panel (can increase cost)

- make arrow keys full size (doesn't cost anything)

- add 7 keys for additional Cyrillic letters and 2 keys to switch between layouts (doesn't cost anything)

- add 3 USB ports and Ethernet (doesn't noticeably increase cost)

- increase RAM limit to 128 Gb (shouldn't cost anything, it is probably just a software limitation)

- use standard 3.5mm audio jacks

Using a better LCD panel can increase cost, so here is how this can be conpensated:

- use an older cheaper CPU. Newest CPUs usually have lower performance to cost ratio and therefore it doesn't make sense to buy them. Also why pay for 10 cores when most of the time you will be using 1 or 2?

- support cheaper HDD instead of SSD

- remove unnecessary speakers

- remove unnecessary keyboard backlight. Using laptop in darkness is bad for eyes anyway.

Also I am surprised that a modern i7 CPU that costs over $470 has just 12Mb cache. You can (probably) buy an old CPU with more cache for smaller price.

comment 4y ago · link · parent

There is a difference. Gecko might implement features that would allow sites to work and look better in Firefox (for example, smoother scrolling, better animations, new CSS/HTML/JS features and so on). But Apple doesn't allow other browser engines, and Firefox cannot use this as an advantage to compete with Safari.

Also, if Apple allowed other browser engines with better support for new features, then web developers might stop caring about supporting Safari. This might be another reason why Apple doesn't want other browsers on their devices.

comment 4y ago · link · parent

This is not a correct measurement. You should also account for memory used by shareable data like binary and libraries, and memory swapped out.

On Linux, one can add PSS to get more or less accurate number.

comment 4y ago · link · parent

As I understand, they use static analysis. So the malicious code can be hidden by obfuscation.

For example, instead of writing

    open('/etc/password')
One can write

    method = calculateMethodName()
    name = calculateEtcPassword()
    geattr(__builtins__, method)(name)

comment 4y ago · link · parent

Is there official documentation about what `str` (without an ampersand) is? For example, documentation [1] says that `str` is a "string slice" (without explaining what "string slice" mean), and then goes on with description of &str.

And a book on Rust [2] says:

> A string slice is a reference to part of a String

This seems wrong, because &str can reference static strings which are not String. And if str, or "string slice" is a "reference", then &str is a reference to a reference?

And later:

> The type that signifies “string slice” is written as &str

But the documentation said that "string slice" is str, not &str.

Also, I wonder, what do square brackets mean when they are used without an ampersand (as s[0..2] instead of &s[0..2])?

Also, is an ampersand in &str the same as an ampersand in &u8 (meaning an immutable reference to u8) or does it have other meaning?

[1] https://doc.rust-lang.org/std/primitive.str.html

[2] https://doc.rust-lang.org/book/ch04-03-slices.html#string-sl...

comment 4y ago · link · parent

But Rust is designed to write high-performance code. If you don't care about performace, you don't really need Rust. Swift or Go seem more readable and easier to use.

comment 4y ago · link · parent

Transpiling to JS is actually a good idea because one could benefit from JIT (as long as your variable types are not too dynamic).

UPD: I looked at the compiled code and currently it is unlikely to be optimized. Also this page [1] shows that the code run in browser can be up to 1000 times slower than in a native Python interpreter.

[1] https://brython.info/speed_results.html

comment 4y ago · link · parent

WASM won't change anything. Python is compiled into bytecode and slowly interpreted. Any optimizations at WASM level won't change the bytecode. For example, they won't turn range()-based loop into a loop with a counter.

Also, it is unlikely that compiling to WASM will be more effective than to native code because browser cannot afford spending as much time on optimization as a native compiler. Therefore WASM will always be slower than a native code.

If you want to benefit from amazing optimizations that were done for JS, then it is better to transpile your Python code directly into JS.

comment 4y ago · link · parent

Python (and JS) is not optimizer-friendly and it is very difficult to write a JIT for it (you can read a description of JIT in WebKit dev blog to get an idea what it takes to write it).

comment 4y ago · link · parent

I didn't write that you need to program your website in C. Obviously it is more convenient to use high-level languages. Everybody wants to write less code. I use Python myself, although not for work. But it would be a good idea to design high-level languages so that it would be easy to compile and optimize them.

For example, JS has no classes and uses prototype inheritance, and you can even change prototype at runtime. This is absolutely useless, inconvenient feature and it makes optimization (like JIT compilation) much more difficult (for example, before calling a method you must ensure that the prototype didn't change, the method was not replaced and so on).

In 95% (arbitrary number) of cases you just need classes with a fixed set of fields and methods known at compile time, which is very optimizer-friendly.

comment 4y ago · link · parent

I notice this too. If I open a SPA there almost always will be a spinning circle and I have to wait like 3 or more seconds before I can see the content. In theory one can write a SPA that would load instantly, but in reality it will be a spinning circle.

I can only imagine how many people will just close the tab and move to next search result.

comment 4y ago · link · parent

Obviously, one loop in Python won't hurt performance. But reality is that people will try to build SPA on this technology. They will port Redux, that uses immutable objects and recreates whole graph of objects on every event. They will try to move SQLAlchemy and Django into the browser. Isn't it cool (for inexperienced developer), you just import a script from CDN and can write Django code? And this will run on a 10-megabytes interpreter in WASM.

Of course if you are writing an internal app and can provide M2 MacBook to every employee, then it is totally fine. But if you are writing applications for wide audience, it is a different thing.

I remember that one of early users of Vkontakte (a Russian clone of Facebook) was impressed that the site was loading fast on his old computer. As I remember, its JS code was written in vanilla JS without libraries like jQuery. Today the hardware is better, but if you will run SQLAlchemy in a browser to save development cost, your site's loading time won't impress users.

comment 4y ago · link · parent

No. People won't write C extensions. They will write something heavy like Redux (which recreates full object graph on every event) in Python.

comment 4y ago · link · parent

I used an empty loop just to simplify an example. Obviousy in real code the loop would do domething useful and wouldn't be optimized out.

comment 4y ago · link · parent

Creating an application is more like building your own car, not merely driving it.

I think it would be great if more people would be able to create web applications, but there should be better technologies than shipping a ten-megabytes interpreter with every HTML page.

Also Python is not easy for non-developers. It might be easy for middle school level tasks like replacing a word in a string. However if you want to use a database, you have to learn about object-oriented programming, property descriptors, ORM and decorators, all of these are difficult topics and libraries like SQLAlchemy are not for beginners (just look at its documentation. It doesn't even explain what ORM means).

comment 4y ago · link · parent

The article describes what is possible with Python in a browser, but misses an important detail: how much memory it consumes and how much CPU it uses.

Python is not a fast language. For example, consider a simple loop:

    for i in range(10):
        pass
In Python, this will be compiled into: a call to range(), heap allocation of an Iterable, calling getIterator() on an Iterable (which might also do allocation), calling next() on an Iterator while catching for StopIteration exception (and calls are often slow in interpreted languages). While in C we could just have a loop without any calls.

I remember how I had to use a Dart-based web application (compiled to JS) in one of Google's advertising products. The script weighed around several megabytes and everything was so slow. Furthermore, there also was a small and useless "what's new" applet, and it probably was shipped with a separate copy of Dart runtime because it weighed several megabytes too. Obviously this was a product intended to be used only on latest MacBooks, not on a Windows XP laptop.

It is totally fine to write such application for youself, or maybe for internal use, but if you are a corporation with millions of users, I think you should pay a little attention to performance and choose a better technology. Or, if you are of a Google scale, find a way to optimize the code.

comment 4y ago · link · parent

I find it suspicious too. As I understand, the fines are not for being a victim of a hack, but for not storing the data properly and securely. Therefore bank should have paid those fines even if it hadn't been hacked.

comment 4y ago · link · parent

Here is something that doesn't feel right. The article says:

> The breach has so far cost US bank Capital One, one of the 30 institutions affected, more than $270m in compensation and regulatory fines.

The bank claims that it is hacker's fault.

But isn't it wrong? Bank was fined and sued not for having been a victim of a hack but for not storing data securily, not configuring the cloud accounts properly. For not following required procedures. Therefore, as I understand, the bank should have been fined even if there were no breach.

Or are they blaming the hacker for exposing the violations? Do they assume that it is ok to violate regulations as long as nobody knowns about it? That's ridiculous.

comment 4y ago · link · parent

Youtube has millions of viewers that could stumble upon your videos. If you host them yourself, you won't get any views.

Main value of Youtube is not their video hosting technology; it's the userbase.

1
108109110
185