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

Highland.js #144

Closed
cshum opened this issue Aug 7, 2015 · 4 comments
Closed

Highland.js #144

cshum opened this issue Aug 7, 2015 · 4 comments
Labels
ENHANCEMENT Something could be better

Comments

@cshum
Copy link
Contributor

cshum commented Aug 7, 2015

Not really an issue. Just another tool may worth looking into: http://highlandjs.org/

Highland is basically a Node.js stream interface for lodash + async.
A very good combination since levelup exposes Node.js Readable stream for querying data.

What may look like using Highland e.g.
https://github.com/fergiemcdowall/search-index/blob/master/lib/matchers/matcher.js

var H = require('highland');

H(reverseIndex.createReadStream({
      start: 'TF~*~' + beginsWith,
      end: 'TF~*~' + beginsWith + '~~~'
}))
.filter(function(data){
  return data.key.substring(data.key.length, data.key.length - 2) == '~~';
})
.map(function(data){
  return [data.key.split('~')[2], data.value.length]; //suggestions
})
.sort(function (a, b) {
  return b[1] - a[1]; //sortedSuggestions
})
.take(10) //splice(0, 10);
.map(function(data){
  return data[0]; //simpleSortedSuggestions
})
.collect()
.pull(callback);

Streaming data can avoid processing the whole batch of arrays into memory.
Which may help when search index reaches certain point of memory consumption.

I am very interested in this project. Would love to send some PRs once I get around with the code.

@mewwts
Copy link
Collaborator

mewwts commented Aug 7, 2015

Hi @cshum! I would not mind at all working with streams through highland. Great to hear of your interest, and PRs are more than welcome! Thanks for contributing 👍

@fergiemcdowall
Copy link
Owner

@cshum thats a good point about how streaming data can avoid processing whole batches of arrays into memory. The code looks great, and would be a most welcome addition to the project.

@fergiemcdowall fergiemcdowall added the ENHANCEMENT Something could be better label Aug 7, 2015
@fergiemcdowall
Copy link
Owner

The highland stuff that has been put in so far is really good.

@fergiemcdowall
Copy link
Owner

Closing for now, and agree with the general principle that streams should be used instead of large arrays wherever possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ENHANCEMENT Something could be better
Projects
None yet
Development

No branches or pull requests

3 participants