question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Why custom ringbuffer used instead of deque?

See original GitHub issue

https://github.com/matthiasplappert/keras-rl/blob/d9e3b64a20f056030c02bfe217085b7e54098e48/rl/memory.py#L42 states: Do not use deque to implement the memory. This data structure may seem convenient but it is way too slow on random access. Instead, we use our own ring buffer implementation.

Not sure why this is stated. I ran this quick test: ` ring = RingBuffer(maxlen = 1000)

start_time = time.time()
for i in range(100000):
    ring.append(i)
print("--- %s seconds ---" % (time.time() - start_time))

d = deque(maxlen=1000)
start_time = time.time()
for i in range(100000):
    d.append(i)
print("--- %s seconds ---" % (time.time() - start_time))

start_time = time.time()
for i in range(100000):
    l = ring[i%1000-1]
print("--- %s seconds ---" % (time.time() - start_time))

start_time = time.time()
for i in range(100000):
    l = d[i%1000]
print("--- %s seconds ---" % (time.time() - start_time))

and got this result: — 0.0608789920807 seconds — — 0.00712609291077 seconds — — 0.0430929660797 seconds — — 0.00617289543152 seconds — `

You can see that the custom ringbuffer is significantly slower than the deque at adding or removing. Can someone explain to me what the comment is referring to exactly and why the ringbuffer is used?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:16 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
kirkschepercommented, May 21, 2018

All my changes are here: https://github.com/kirkscheper/keras-rl/tree/recurrent-ddpg

I have been playing around with lots of different things that are probably not directly ready for a pull request.

1reaction
matthiasplappertcommented, Feb 5, 2018

Cool, feel free to update the code to use deque. I’m not sure anymore why I thought deque was too slow but it seems like this was clearly not true.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What's the difference between a deque and circular buffer?
a fixed sized deque that serves as a memory can have its oldest value replaced (although we an remove new values). a circular...
Read more >
Creating a Circular Buffer in C and C++ - Embedded Artistry
Circular buffers are often used as fixed-sized queues. The fixed size is beneficial for embedded systems, as developers often try to use static ......
Read more >
c++ - Ring Buffer Implementation in C++14
A ring buffer or circular buffer is a fixed sized queue that advances head and tail pointers in a modulo manner rather than...
Read more >
Performance of a Circular Buffer vs. Vector, Deque, and List
Queues are important, frequently used data structures. A queue is a container for data. It has two ends, labeled the front and back....
Read more >
Optimizing a copy-on-write double-ended queue in Swift
Instead, I'll focus on the challenges involved in implementing a ... There is an existing, commonly used Deque implementation which appears ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found