ワールドニュース strat_ai_server
-
Monoslices: Generate specialized slice operations for a 2-10× speedup
golangbridge | 2026-10-02 05:55 | id : 164089
The standard library’s slices package includes a number of operations that take function arguments to control their behavior: SortFunc, EqualFunc, etc. These operations are flexible, but they control their behavior using function parameters, which can inhibit compiler optimizations, and they can do a lot of copying, internally and to pass slice elements to those functions by value. As a result, they can leave a lot of performance on the table. To solve this, I wrote monoslices: a tool that generates specialized (“monomorphic”) versions of the slices.*Func operations. monoslices is not a library. It generates code that gets checked into your project and adds no module dependencies. The generator itself is intended to be installed as a tool dependency in your project, which helps with versioning and toolchain consistency: go get -tool github.com/zolstein/monoslices Then, it’s invoked with: go tool monoslices from the CLI, or via go generate. Instead of writing: slices.SortFunc(records, compareRecords) you declare compareRecords as the comparator for a generated set of operations: func compareRecords(a, b Record) int { … } //monoslices:generate name=Records cmp=compareRecords and monoslices generates functions like: func RecordsSort(s []Record) func RecordsBinarySearch(s []Record, target Record) (int, bool) func RecordsMin(s []Record) Record These generated functions are based on the standard library implementations, but call compareRecords directly. As a result, the compiler has much more room to optimize. It also supports specialization functions that receive pointers to elements instead of copies, using the byref option: func compareRecords(a, b *Record) int { … } //monoslices:generate name=Records cmp=compareRecords byref=true How much this matters depends heavily on the operation and element type. Some cases already get optimized well and there’s basically no difference. But for many operations, the difference is substantial, and byref benefits even moderately sized values: Operation 16 B value 64 B by-ref 256 B by-ref Equal 1.6-2.0× speedup 3.3-5.9× speedup 3.4-10× speedup BinarySearch 1.7-1.9× speedup 1.8-2.3× speedup 2.9-3.8× speedup Sort 1.7-2.1× speedup 3.3-4.0× speedup 4.2-5.3× speedup Part of the reason I wrote this was to explore the performance impact of specialization in Go. Specialization is an important part of how languages like Rust and C++ generate efficient generic code. Generic Go code can’t specialize in all the same ways, and I wanted to see how much difference explicit specialization would make for some common Go operations. It turns out that, at least for some of them, the difference is pretty large. I hope to see better support for this kind of optimization in Go over time, whether that’s through language changes, compiler improvements, or better codegen tooling and a culture that encourages writing code generators like this. 3 posts - 2 participants Read full topic
-
Japan's first mayor to take maternity leave lands on TIME100 Next list
bbc_world | 2026-10-02 05:53 | id : 164123
Shoko Kawata's maternity leave drew mixed reactions in Japan, a country struggling to lift birth rates.
-
(WLCGF.PK) | Stock Price & Latest News - Reuters
reuters_business | 2026-10-02 05:51 | id : 164371
(WLCGF.PK) | Stock Price & Latest News Reuters
-
0392.F - | Stock Price & Latest News - Reuters
reuters_business | 2026-10-02 05:46 | id : 164354
0392.F - | Stock Price & Latest News Reuters
-
Friday briefing: How we covered the flydubai incident as it unfolded
guardian_world | 2026-10-02 05:45 | id : 164102
In today’s newsletter: When a passenger plane plunges 17,000ft amid claims of terrorism, hijacking and geopolitical intrigue, Guardian journalists have to try and separate fact from fiction in real timeGood morning. Shocking news of a cockpit stabbing. Graphic footage of bloodied crew members. Mid-air testimony from terrified passengers.This was the tenor of the heart-in-mouth reporting as the horrifying events unfolded onboard flight FZ 1073 to Tel Aviv: the early morning budget flight that plummeted 17,000ft in under two minutes before the courageous intervention of passengers and crew averted an apparent hijacking, potentially saving the lives of not just the 170+ passengers and crew on board, but many more.UK politics | Ministers are working up sweeping plans for welfare changes including scrapping a key disability benefit for under-25s and replacing it with a multibillion-pound package of support to get into work.Northern Ireland | Talks aimed at resolving the Drumcree parade dispute have broken up without agreement, with Northern Ireland secretary Chris Bryant describing the situation as being between a “rock and a hard place”.US news | Tennessee’s governor has suspended all executions in the state and ordered an independent inquiry after a botched attempt to put a condemned inmate to death on Wednesday night.AI | When prompted, AI chat bots will edit images to remove the hijabs from Muslim women, a violation of one of the world’s most common and visible expressions of faith.Europe news | A fast-growing protest by high-school students over long hours, teacher shortages and decaying facilities has escalated into “urban violence”, the French government has warned. Continue reading...