Git Product home page Git Product logo

Comments (5)

bpsm avatar bpsm commented on September 26, 2024

Yes, that's a bug, though what this commit says is true: ArrayLists are indeed better than LinkedLists in that they use less memory and are faster to iterate.

Hanging the whole List/Vector distinction on the presence or absence of the RandomAccess marker interface is a bit of a hack. I'm not very happy with it and find myself wishing for Clojure-like meta-data. This strategy also presents a problem for edn-java-guava, since Guava's immutable list classes all implement RandomAccess.

Two alternatives that might be better than reverting the commit above to return java.util.LinkedList implementations:

  1. Return a java.util.List which merely wraps a java.util.ArrayList, but does not itself implement RandomAccess.
  2. Return a custom implementation of java.util.List which chunks by actually being a list of fixed-size chunks under the hood.

The downside of doing nothing is what this issue is about. The downside of 1 is the additional indirection introduced for delegation. (Though Iteration can be direct.) The downside of 2 is the implementation effort and probability of introducing bugs.

I'm thinking the first approach sounds like it's worth it; the second is unlikely to be worth it.

What do you think?

from edn-java.

bpsm avatar bpsm commented on September 26, 2024

See https://github.com/bpsm/edn-java/commits/feature/issue32

from edn-java.

mikera avatar mikera commented on September 26, 2024

Why not just do a lightweight custom implementation of ArrayList? I don't think chunking actually buys us anything here, indeed it's probably going to add more overhead than an extra layer of indirection.

If you are interested in that approach, I think I've got some old code hanging around that would get us 80% there....

from edn-java.

abernard avatar abernard commented on September 26, 2024

Ben,

I agree with your rationale. LinkedList has poor performance characteristics and option 2 seems like asking for trouble. Your provided solution is quite clean.

On the issue of this handling Guava collections, I wonder if the code to determine List or Vector should be separated out into an interface. This would be something like:

interface SequenceTypeSelector {
    boolean isVector(Object o);
}

The selector could be attached to the ProtocolBuilder for the Printer (with a default implementation provided of course). Extending SequenceTypeSelector would allow custom dispatch for types, allowing the simple if-else select on java.util.RandomAccess, or a Map lookup for more complex type hierarchies.

from edn-java.

bpsm avatar bpsm commented on September 26, 2024

I'm going to release https://github.com/bpsm/edn-java/commits/feature/issue32 as 0.4.2. Making distinguishing between list and vector pluggable as been moved to issue #33 and tentatively assigned to milestone 0.5.0.

from edn-java.

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.