[{"data":1,"prerenderedAt":220},["ShallowReactive",2],{"project-40177694":3},{"id":4,"name":5,"line":6,"line_source":7,"title":8,"url":9,"domain":10,"maker":11,"posted_at":12,"year":13,"points":14,"comments":15,"rank_in_year":16,"shown_in_year":17,"top":18,"tier":19,"category":20,"subcategory":21,"format":22,"keywords":23,"reception":28,"sentiment":29,"stance_mix":30,"scored_comments":35,"aspects":36,"strip":40,"post_text":42,"what":43,"said":67,"maker_in_thread":143,"shape":151,"grid":155,"attempts":181,"same_week":182,"maker_shows":34,"maker_hidden":212,"reader_version":213,"card":214},"40177694","Sleepsort","Sorting While Sleeping","title","Show HN: Sleepsort – Sorting While Sleeping","https:\u002F\u002Fanimeshchouhan.com\u002Fposts\u002Fsleepsort\u002F","animeshchouhan.com","animeshchouhan",1714198332,2024,14,15,2205,3515,63,"shown","languages","sorting algorithm demo","library",[24,25,26,27],"sleep sort","sorting algorithm","async python","asyncio","curious",-0.105,{"positive":31,"neutral":32,"mixed":33,"critical":34},1,5,0,2,8,{"idea":37,"execution":38,"performance":39},{"positive":31,"critical":33},{"positive":33,"critical":33},{"positive":33,"critical":34},[32,33,41,41,33,33,31,33,41,33,41,33,41,31,33],3,"My take on sleepsort.",{"problem":44,"audience":53,"pricing":53,"motivation":53,"time_to_build":53,"stack":54,"openness":66,"stage":66,"team_size":66},{"value":45,"source":46,"evidence":47},"Demonstrates sorting by delaying values with sleep, as a joke or toy algorithm.","inferred",[48,50],{"id":49},"post",{"id":51,"by":11,"text":52},"40196743","It's a toy sorting algorithm and isn't meant for production use anyways as it isn't efficient and lacks predictability.",null,[55,63],{"value":56,"source":57,"evidence":58},"Python","commenter",[59],{"id":60,"by":61,"text":62},"40187358","0x45696e6172","I really liked this article. It's the first time I see async Python used to solve a problem. Suggestion: I think it would make sense to use softmax as the scaling function. This…",{"value":27,"source":57,"evidence":64},[65],{"id":60,"by":61,"text":62},"unknown",{"praise":68,"objections":73,"requests":100,"questions":121,"alternatives":130},[69],{"value":70,"source":57,"evidence":71},"Liked the article and the use of async Python to show a problem",[72],{"id":60,"by":61,"text":62},[74,85],{"value":75,"source":57,"evidence":76},"Not suitable for production; sleep timing is not precise and the algorithm is inefficient",[77,81,82],{"id":78,"by":79,"text":80},"40187811","Charon77","In case you're thinking of using this in production (please don't) Keep in mind that there's a general limitation in most sleep implementation across languages. sleep(x)…",{"id":51,"by":11,"text":52},{"id":83,"by":11,"text":84},"40196781","Well, the scheduler will process all tasks parallelly, but this too would have its limits. This technique has many pitfalls and is therefore not meant for any practical use.",{"value":86,"source":57,"evidence":87},"Sorting happens in the scheduler, so calling it sleep sort is misleading",[88,92,96],{"id":89,"by":90,"text":91},"40186868","datascienced","The scheduler itself presumably uses an in memory tree to sort the values it is given so probably that is where the real sorting happens.",{"id":93,"by":94,"text":95},"40187178","qsort","Bingo. Whenever new coroutines are scheduled to be executed sometime in the future, something somewhere needs to keep them sorted so that the event loop knows how to dequeue…",{"id":97,"by":98,"text":99},"40187568","dspillett","But it doesn't have to work that way. The scheduler could scan the whole (unsorted) list at each tick to see if anything is due. No scheduler worth a jot in production is going…",[101,108],{"value":102,"source":57,"evidence":103},"Use softmax or better scaling to handle outliers and negative numbers",[104,105],{"id":60,"by":61,"text":62},{"id":106,"by":11,"text":107},"40196761","Yeah totally agree, it would need a better scaling function to tackle outliers. The basic scaling was just to give an idea of how this could be improved. We can always devise…",{"value":109,"source":57,"evidence":110},"Preprocess data with an order-preserving hash to pre-sort",[111,115,118],{"id":112,"by":113,"text":114},"40187383","yobbo","Also, if you know the distribution of the values, you can achieve sorting or pre-sorting by a letting an order-preserving \"hash-function\" fill a table, so O(N).",{"id":116,"by":11,"text":117},"40196798","Yes, that is true for any sorting algorithm. We can always achieve better results if we preprocess the data on some parameters. Thanks for your feedback, will try to incorporate…",{"id":119,"by":113,"text":120},"40198997","Sleepsort is like a hash-based sort using sleep(x) instead of a hash function h(x). You can see more here: https:\u002F\u002Fpages.cs.wisc.edu\u002F~siff\u002FCS367\u002FNotes\u002Fsorting.html The function…",[122],{"value":123,"source":57,"evidence":124},"What happens when the list is so large that processing takes longer than the largest value?",[125,129],{"id":126,"by":127,"text":128},"40187818","personalityson","What if the list is so large it takes more seconds to process than the highest value in the list?",{"id":83,"by":11,"text":84},[131,136],{"value":132,"source":57,"evidence":133},"Hash-based sorting with an order-preserving function",[134,135],{"id":112,"by":113,"text":114},{"id":119,"by":113,"text":120},{"value":137,"source":57,"evidence":138},"Scheduler-based sorting via niceness or process priorities",[139],{"id":140,"by":141,"text":142},"40187469","delusional","Theoretically I'd think you could do the same with niceness. Start a bunch of processes, have them wait on some condition, set their niceness to the value and fire the condition.…",{"comments":144,"answered":31,"key":145},6,[146,147,150],{"id":106,"text":107},{"id":148,"text":149},"40196973","Well, this would depend totally on how the scheduler has been implemented. I will give you an analogy for a simple implementation: Suppose we receive 10 numbers as inputs. We set…",{"id":51,"text":52},{"commenters":152,"max_depth":41,"maker_replies":144,"first_comment_mins":153,"lifespan_hours":154},9,1547,57,[156,158,160,162,164,166,167,169,171,172,174,176,177,178,179],[60,33,32,157,61,33],"project\u002Fpositive\u002Fidea",[106,33,33,159,11,31],"maker\u002Fneutral\u002Fexecution",[89,31,41,161,90,33],"project\u002Fneutral\u002Fexecution",[93,31,41,163,94,33],"project\u002Fneutral\u002Fidea",[97,31,33,165,98,33],"commenter\u002Fneutral\u002Fidea",[148,31,33,165,11,31],[78,34,31,168,79,33],"project\u002Fcritical\u002Fperformance",[51,34,33,170,11,31],"maker\u002Fneutral\u002Fidea",[140,41,41,163,141,33],[173,41,33,170,11,31],"40196769",[112,175,41,161,113,33],4,[116,175,33,159,11,31],[119,175,41,163,113,33],[126,32,31,168,127,33],[83,32,33,180,11,31],"maker\u002Fneutral\u002Fperformance",[],[183,188,193,198,202,207],{"id":184,"name":185,"points":186,"category":187},"40159278","NAND",420,"learning_science",{"id":189,"name":190,"points":191,"category":192},"40210627","Extension.js",381,"dev_tools",{"id":194,"name":195,"points":196,"category":197},"40213562","where to stream",335,"consumer_social",{"id":199,"name":200,"points":201,"category":192},"40191510","Dotenv",225,{"id":203,"name":204,"points":205,"category":206},"40222051","Factful",222,"ai",{"id":208,"name":209,"points":210,"category":211},"40173237","Lanki",206,"productivity",false,"v2",{"id":215,"name":5,"line":6,"ai":212,"cat":20,"year":13,"points":14,"comments":15,"rec":28,"s":216,"top":18,"kw":217,"maker":11,"domain":10,"tier":19,"attempts":33,"strip":218,"url":9,"mix":219,"praise":70,"objection":75,"sub":21},40177694,-0.1,[24,25,26,27],"503300103030310",[31,32,33,34],1794036653817]