RC

Sep. 12th, 2019 12:26 pm
thedeemon: (Default)
[personal profile] thedeemon
В интернетах обсуждают очередное сравнение скорости работы разных языков, на этот раз на примере user mode сетевых драйверов. С непреодолим как скорость света. Раст отстает, то ли из-за bounds checks, то ли из-за другого кодогенератора (LLVM vs. GCC). Неожиданно хорошо выступил C#, там есть value типы и слайсы/спаны, можно снизить нагрузку на GC до нуля практически, есть unsafe блоки и указатели. Близко к нему Go. Java отстала. Окамл получился быстрее Хаскеля. Но самый позорный результат из компилируемых языков - у Swift'a. И ведь не первый раз я вижу, что он так тормозит. Комментарии из их статьи:

Swift increments a reference counter for each object passed into a function and decreases it when leaving the function. This is done for every single packet as they are wrapped in Swift-native wrappers for bounds checks. There is no good way to disable this behavior for the wrapper objects while maintaining an idiomatic API for applications using the driver. A total of 76% of the CPU time is spent incrementing and decrementing reference counters. This is the only language runtime evaluated here that incurs a large cost even for objects that are never free’d.

Вот вам и "RC быстрее GC".

Занятное про Хаскель:
Compiler (GHC 8.4.3) optimizations seem to do more harm than good in this workload. Increasing the optimization level in the default GHC backend from O1 to O2 reduces throughput by 11%. The data in the graph is based on the LLVM backend which is 3.5% faster than the default backend at O1. Enabling the threaded runtime in GHC decreases performance by 8% and causes the driver to lose packets even at loads below 1 Mpps due to regular GC pauses of several milliseconds.

Date: 2019-09-12 01:32 pm (UTC)
juan_gandhi: (Default)
From: [personal profile] juan_gandhi
Забавные наблюдения.

Тут, конечно, сравнивается, пожалуй, не скорость языков, а скорость относительно небольшого хорошо вылизанного кода на разных языках.

Но интересно все равно.

Date: 2019-09-12 04:35 pm (UTC)
perdakot: (Default)
From: [personal profile] perdakot
Вот вам и "RC быстрее GC".
Swift increments a reference counter for each object passed into a function and decreases it when leaving the function.

А ГЦ же даже больше должен делать, создать ссылку, зарегистрировать ее везде и обратно.

Date: 2019-09-12 05:32 pm (UTC)
chaource: (Default)
From: [personal profile] chaource
As far as I understand, GC does not necessarily work like that. Some GC implementations walk the heap and find pointers that are unused.

Date: 2019-09-12 05:47 pm (UTC)
perdakot: (Default)
From: [personal profile] perdakot
А корни берутся из стэк фреймов, где ссылки хранятся в виде указателей и ГЦ знает куда смотреть? Как тогда куча уплотняется (указатели правятся прямо в стэке)?

Date: 2019-09-12 10:53 pm (UTC)
chaource: (Default)
From: [personal profile] chaource
GC is a well developed field with 500-page books full of GC algorithms. I wouldn't know what made Ocaml faster than GHC, for example.

I read somewhere that Standard ML has an experimental compiler called "MLTon" that eliminates all garbage collection by whole-program optimization. Not sure if this is really possible in all cases.

Date: 2019-09-13 12:35 am (UTC)
perdakot: (Default)
From: [personal profile] perdakot
eliminates all garbage collection by whole-program

Rust этим занимается с лайфтаймами, поэтому двухсвязный список в нем нетривиален.

Date: 2019-09-14 05:29 am (UTC)
From: [personal profile] sassa_nf
Generated code has safe points where all pointers are in known places in memory, not in registers. Yes, the pointers are modified in place.

There are methods that allow to do less of this, trapping mutators by marking relocated regions as read only or missing.

Date: 2019-09-13 07:10 am (UTC)
vit_r: default (Default)
From: [personal profile] vit_r
Проблема с высоконагруженными приложениями в том, что нужна компиляция без side-effects. То есть, можно бросить на отладку лишние силы, добрав пять процентов, и сама постановка вопросов не имеет смысла.

В задаче же с большими объектами и графическим интерфейсом важно время реакции. И тут, подозреваю, скорости будут другие.

Интересно, кстати, было бы посмотреть на С++.

Date: 2019-09-13 09:48 am (UTC)
vit_r: default (Default)
From: [personal profile] vit_r
Не получается у человечества безопасный код на Си писать, десятилетиями пытались.

Человеки разные бывают. Всё-таки от организации производства очень многое зависит.

Date: 2019-09-14 05:46 am (UTC)
From: [personal profile] sassa_nf
Java is full of JNI. That's expensive, and is a nonsensical way of implementing it. When we worked on ixgbe, we implemented a NativeByteBuffer, then all accesses are normal Java, only allocation and some forms of polling required JNI.

Our RT was 100 usecs.

Profile

thedeemon: (Default)
Dmitry Popov

December 2025

S M T W T F S
 12 3456
789101112 13
14151617181920
21222324252627
28293031   

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jan. 28th, 2026 08:18 pm
Powered by Dreamwidth Studios