Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hashtbl.remove/clear never shrink the internal bucket array #5555

Closed
vicuna opened this issue Mar 26, 2012 · 5 comments

Comments

Projects
None yet
2 participants
@vicuna
Copy link

commented Mar 26, 2012

Original bug ID: 5555
Reporter: Christoph Bauer
Assigned to: @lefessan
Status: closed (set by @xavierleroy on 2015-12-11T18:04:51Z)
Resolution: fixed
Priority: normal
Severity: minor
Version: 3.12.1
Fixed in version: 4.00.0+dev
Category: standard library
Monitored by: @rixed mehdi "Julien Signoles" @yakobowski

Bug description

The internal bucket array of an hashtable grows in Hashtbl.add/replace,
but neither Hashtbl.remove nor Hashtbl.clear shrink the table.

@vicuna

This comment has been minimized.

Copy link
Author

commented May 15, 2012

Comment author: @lefessan

A new function Hashtbl.reset has been added to resize the bucket table to its initial size.

@vicuna

This comment has been minimized.

Copy link
Author

commented May 15, 2012

Comment author: @rixed

It's not quite resizing. So the user is supposed to track the size of the hash and reset it when judged appropriate ?

@vicuna

This comment has been minimized.

Copy link
Author

commented May 15, 2012

Comment author: @lefessan

True, it's not resizing, it is clearing and resetting to the initial size. Users should only use it if they need to recover some space, otherwise, they probably want to keep the current size and just clear all entries.

@vicuna

This comment has been minimized.

Copy link
Author

commented May 15, 2012

Comment author: @rixed

Oh, reading your comment then the actual diff I realize that reset also clears the hashtbl.

I then respectfully disagree with closing this ticket, then.
That's very nice to have both clear and reset behavior (but I'd favor to add an optional boolean argument to clear that would additionnally shrinks the hash size).

It seams to me that the initial concern was that when using long lived hashtables which sizes may vary in great proportion then the overall size of all hashtable growth continuously, which hurts memory and thus performances.

I understand that shrinking dynamically a hash is a tedious topic (one must avoid to continuously grow/shrink), though.

@vicuna

This comment has been minimized.

Copy link
Author

commented Jun 6, 2012

Comment author: Christoph Bauer

I would have expect, that Hashtbl.remove calls resize like add, if the table is less than 3/8 (or 1/4) full.

@vicuna vicuna closed this Dec 11, 2015

@vicuna vicuna added the stdlib label Mar 14, 2019

@vicuna vicuna added the bug label Mar 20, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.