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

Optimizing boolean arrays #5845

Closed
vicuna opened this issue Dec 5, 2012 · 2 comments
Closed

Optimizing boolean arrays #5845

vicuna opened this issue Dec 5, 2012 · 2 comments

Comments

@vicuna
Copy link

vicuna commented Dec 5, 2012

Original bug ID: 5845
Reporter: thomasblanc
Assigned to: @alainfrisch
Status: closed (set by @xavierleroy on 2015-12-11T18:08:27Z)
Resolution: won't fix
Priority: low
Severity: feature
Category: ~DO NOT USE (was: OCaml general)

Bug description

I don't know if it's possible but it seems that double arrays are optimized so maybe it could be possible to do so with boolean arrays.

I find to use bool array way more intuitive and flexible than ints, specially because I sometimes don't know the size of my array and don't want to risk an error. After all, 31 bits is small.

So, how difficult would it be to make a boolean array something like an array of ints and let the compiler handle the painful xor, lsr and friends ?

@vicuna
Copy link
Author

vicuna commented Dec 5, 2012

Comment author: @alainfrisch

I'm marking this ticket as "won't fix" since I'm pretty sure the request of adding a special "automatic" runtime representation for bool arrays will not be granted.

It would be much better to have a specialized "bit field" data structure (probably implemented on top of strings). Btw, one can argue that it's not so great to have a special representation for float arrays: it adds complexity to the runtime system, limits some optimizations (e.g. for shortcutting lazy values) and imposes a runtime overhead to all array operations (in polymorphic contexts, at least).

@vicuna
Copy link
Author

vicuna commented Dec 5, 2012

Comment author: @gasche

Indeed: I believe there is a (weak) consensus that hardcoding the representation of float arrays was a mistake because it cause various pains in the compiler, runtime system and even metatheory (it's one of the reason why top types are not admissible in OCaml) of the language. We could instead use a specialize, monomorphic datastructures such as Bigarray which provides solid efficiency without the hacks.

The solution here is the same: use a specialized data structure. This can be developed as a third-party library so doesn't need to be in the compiler.

(On a slightly different note, integer bit operations are sometimes a bit disappointing in OCaml because the tagging logic makes them less efficient as they could be. If in the course of developping such a bit-packing library you discover situations where small specialized compile-time optimizations would make an important difference on real-world benchmark, you can contact Pierre Chambart which is interested in working on this kind of optimizations and, maybe, getting them integrated in the compiler.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants