Giter Site home page Giter Site logo

Comments (3)

szeiger avatar szeiger commented on June 3, 2024

More generally we need to compare all implementations in this project with the current collections library to get the necessary bug fixes and performance improvements. This started out as a strawman proposal for a new design, we shouldn't expect that the current implementations are correct or fast.

from collection-strawman.

Ichoran avatar Ichoran commented on June 3, 2024

Sometime soon we need an initial go/no-go decision on this design. Once it's "go", or even once we anticipate it being "go", we can start worrying about correctness and performance. (Of course if a design would prevent correctness or performance, we should evaluate it earlier.)

Anyway, with regard to buffer resizing, I usually personally use a clipped bit shift operation that uses values of size (1 << n)-1, but in some cases it is essential that we have powers of two, and it's kind of nice if the sizes always agree just to keep it conceptually simpler. Given that array overhead is around 20 bytes and compressed pointers are 4, allocating less than 4 things into an array seems highly questionable.

In my usual fast-and-dirty benchmarking, allocating an array of AnyRef of length 4 is about 25% slower than allocating an array of length 2; 8 is about 45% slower than 4; and 16 is about 66% slower than 4, roughly consistent with an array creation model of 1.5 ns + 0.3 ns / object pointer. Obviously this will vary by machine, but unless we're sure that we need tiny arrays only, I would say that 8 is probably the way to go.

This suggest an algorithm like

val twice = end * 2
val newSize = 
  if (twice < 0) {
    if (end == Int.MaxValue) throw new Exception("TODO--write sane message")
    else Int.MaxValue
  }
  else if (twice < 8) 8
  else twice

is the way to go. In my tests this barely slows things down at all in a tight loop.

from collection-strawman.

julienrf avatar julienrf commented on June 3, 2024

I implemented this algorithm in bbcb391 (in the benchmark branch, because they were preventing ArrayBuffer benchmarks to run)

from collection-strawman.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.