Hacker News new | ask | show | jobs
by hobs 3687 days ago
I was taking the point of "Why is the problem taking so long when it seems like a simple thing to calculate?" which was a little orthonogal from theme of the total post, so I can see why there would be some confusion.

The article talked about 30 minutes to run through a "is this set of items in this other set of a bunch of items".

While it would probably make sense to do this efficiently in memory the reality is the company mentioned are probably doing it inefficiently in memory; asking some tool which can do this type of work effectively and is fairly well known was my basic suggestion.

1 comments

Why hit the network/a central resource when you could just do it locally?
It's a webapp, they're likely already querying all the meal information from a mysql or postgresql db. Chances are they could have made a change to their db models and written some sql to handle food requirements checking instead of handling it after the query. But that could've been premature optimization ultimately, and to speed it up now, it's probably easier to optimize the slow ruby code with some rust instead.
Exactly, I dont mean to beat a dead horse, but most bog standard web apps have the quoted items in a db anyway, and these are very common problems.

For example if we have a few tables we can determine which menu items a user could eat:

  users
  user_ingredient_exclusions
  ingredients
  menu_ingredients
  menu

  -- items a user can eat based on not having any items in the excluded   list
  select distinct m.*
  from menu m
  inner join menu_ingredients mi on m.id = mi.menu_id
  left join user_ingredient_exclusions e on e.ingredient_id = mi.ingredient_id
  inner join user u on u.id = e.user_id
  where e.id is null
  and u.id = @id
Sometimes, it'll be faster.
Unless you specify some asymmetry it will always be faster to do it locally.