Skip to content

Exposing explicit stack allocation #7

@LifeIsStrange

Description

@LifeIsStrange

Hi,
I recently looked at the differences between the implementations of the fastest java and C# algorithms for the benchmarckgame:
The benchmarkgame is arguably the most popular comparative language microbenchmark and C# stands out by being by far the fastest GC based language on it.
There are many reasons for this (explicit SIMD, explicit inlining, use of PCRE, scoped manual memory management, value types, etc)

Among those comparative advantages, there is one kind of optimization that it can do that java cannot currently express: I talk about explicit stackallocation through either the stackalloc keyword for arrays or the Span collection.
(which you can see used here for example)
https://benchmarksgame-team.pages.debian.net/benchmarksgame/program/revcomp-csharpcore-7.html
https://docs.microsoft.com/en-us/dotnet/api/system.span-1?view=net-5.0

So In addition to the current version of this proposal, I make the case for exposing explicit stack allocation to the language (and not just the JVM), I also believe that it is complimentary with the incoming value types https://openjdk.java.net/jeps/401 and exposing such an optimization would enable overall a more performant java ecosystem which translate into a massive value proposition for the industry.

Note that rust has this famous library that offer a growable array that is allocated on the stack if small and if it grows beyond a certain size then it is moved on the heap. Such an optimization for JVM vectors could also make sense ?
https://github.com/servo/rust-smallvec

What do you think ? :)
@karianna

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions