В интернетах обсуждают очередное сравнение скорости работы разных языков, на этот раз на примере 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.
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.
no subject
Date: 2019-09-12 01:32 pm (UTC)Тут, конечно, сравнивается, пожалуй, не скорость языков, а скорость относительно небольшого хорошо вылизанного кода на разных языках.
Но интересно все равно.
no subject
Date: 2019-09-12 04:35 pm (UTC)А ГЦ же даже больше должен делать, создать ссылку, зарегистрировать ее везде и обратно.
no subject
Date: 2019-09-12 05:32 pm (UTC)no subject
Date: 2019-09-12 05:47 pm (UTC)no subject
Date: 2019-09-12 06:07 pm (UTC)Бывают и более простые подходы. Например, в D сборщик просто весь стек сканирует, и все, что похоже на указатель по значению (
делится на величину слова[upd: не обязательно], "указывает" на нужный диапазон адресов), считает потенциальным указателем.А в Окамле тоже просто: там указатели от неуказателей отличаются младшим битом всегда, поэтому разобраться элементарно.
no subject
Date: 2019-09-12 10:53 pm (UTC)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.
no subject
Date: 2019-09-13 12:35 am (UTC)Rust этим занимается с лайфтаймами, поэтому двухсвязный список в нем нетривиален.
no subject
Date: 2019-09-13 09:31 am (UTC)no subject
Date: 2019-09-13 09:28 am (UTC)http://www.mlton.org/Regions
Там были исследования по region inference, но по сути провалились.
no subject
Date: 2019-09-14 05:29 am (UTC)There are methods that allow to do less of this, trapping mutators by marking relocated regions as read only or missing.
no subject
Date: 2019-09-13 07:10 am (UTC)В задаче же с большими объектами и графическим интерфейсом важно время реакции. И тут, подозреваю, скорости будут другие.
Интересно, кстати, было бы посмотреть на С++.
no subject
Date: 2019-09-13 09:36 am (UTC)Но если скорость - самое важное, а на остальное наплевать, тогда да, С is king.
И да, С++ там напрасно нет.
no subject
Date: 2019-09-13 09:48 am (UTC)Человеки разные бывают. Всё-таки от организации производства очень многое зависит.
no subject
Date: 2019-09-14 05:46 am (UTC)Our RT was 100 usecs.