|
revmoo posted:Can someone explain in a simple way what is the fastest way to append an object onto a JS array? I've seen a ton of benchmarks proving different things and I'm having a hard time deciding which method is fastest. I'm working on an app now that does around a million of these types of operations per minute and will need to scale to probably 5 million so even slight performance increases will be noticeable. I think that if you're doing this much processing, browser side / JS maybe isn't the place to do it. What kind of performance are you getting now?
|
# ? Apr 24, 2014 20:29 |
|
|
# ? Jun 5, 2024 05:49 |
|
peepsalot posted:Are you sure that array appending is where you program is spending most of its time? Are you profiling your code? Yes, quite a bit actually. The app is a live mapping application that renders thousands of dots in real-time with events and also has a logging backend so there is a whole lot of dynamic things happening on a relatively tight polling interval. The app is pretty watertight at this point, I've spent the last few days going through and fixing bottlenecks, and it runs extremely smoothly now, I'm just looking for the last of the low-hanging fruit. After looking at those benchmarks in different browsers, it looks like the best compromise in my situation is the arr.length method. I could use push() and get slightly better performance in Chrome but I'm not sure it's worth it. I think at this point the only additional speedups I'd see would be to find a better way to search arrays rather than just looping over them. It seems like there should be a smarter way to locate specific objects in an array based on their contents than just looping over the whole thing, but I have no idea.
|
# ? Apr 24, 2014 20:47 |
|
revmoo posted:Yes, quite a bit actually. The app is a live mapping application that renders thousands of dots in real-time with events and also has a logging backend so there is a whole lot of dynamic things happening on a relatively tight polling interval. The app is pretty watertight at this point, I've spent the last few days going through and fixing bottlenecks, and it runs extremely smoothly now, I'm just looking for the last of the low-hanging fruit. After looking at those benchmarks in different browsers, it looks like the best compromise in my situation is the arr.length method. I could use push() and get slightly better performance in Chrome but I'm not sure it's worth it. I don't know how well it would work with the amount of data your using, but I've been basically appending properties to my array of things where the value is the index of the data. My data sets are much, much smaller than yours. code:
|
# ? Apr 24, 2014 21:00 |
|
Reality posted:I don't know how well it would work with the amount of data your using, but I've been basically appending properties to my array of things where the value is the index of the data. My data sets are much, much smaller than yours. Just want to pipe up and mention that I did something like that a long time ago and it became a maintenance nightmare. This was before even half good debuggers were available, though, so it might be less these days. Keeping a second object around to store indexes (or even object references) might be less annoying in the long run.
|
# ? Apr 24, 2014 21:49 |
|
Ok yeah I was thinking break. That clears up a lot, thanks folks.
|
# ? Apr 24, 2014 21:55 |
|
peepsalot posted:If you don't trust others' benchmarks then maybe do your own? There's probably a lot of variation depending on which js vm you are running in. You can't store object references in typed arrays. It would be a security nightmare. It also matters how big your array is: when it exceeds capacity, it'll be reallocated, which often involves copying the data. Depending on how much work you do per element, that can be meaningful. Pre-sizing arrays can work in surprising ways, because engines usually have a limit beyond which they either don't preallocate at all, or clamp the size of the storage. I'd say to use a[length] = newThing; because it will keep you in the hot generated-code path except for the storage growth case (in all engines I'm familiar with). Calling out to a native incurs a meaningful overhead, though it's distorted in the micro benchmark case. The advice to measure your workload is wise, though. Edit: you can use Array.prototype.indexOf for object identity, but for contents you want a secondary index for sure. I'm not sure how else the problem can be approached, independent of the language. Subjunctive fucked around with this message at 22:37 on Apr 24, 2014 |
# ? Apr 24, 2014 22:34 |
|
Lumpy posted:return will end the execution of a function immediately regardless if you are in a loop, switch or whatever as soon as it's hit. In fact, jslint will complain about this pattern: JavaScript code:
JavaScript code:
|
# ? Apr 24, 2014 23:07 |
|
Anyone willing to look over some code and comment? This is my first real project with JS, so I'm not sure if I'm doing anything horribly wrong. The repo is at https://github.com/olslash/impressive-tweets... relevant is impressive-tweets.js and home.html There's a demo up at http://pacific-citadel-5007.herokuapp.com Thank you kind goons edit: I especially need help with my twitter API search calls... for example result_type=recent doesn't seem to do anything (I get results from 2008 and 2014 mixed together) and language=en doesn't either (i get a lot of Japanese results). edit: I refactored quiet a bit in the last few hours, in case anyone had looked. Fish Ladder Theory fucked around with this message at 08:09 on Apr 25, 2014 |
# ? Apr 24, 2014 23:09 |
I'm writing a 'lil incremental game ala Cookie Clicker and the like, and I want to try and hide some of the upgrades from the end user. At the moment, the details are stored in plaintext JSON on the server, so I'm restricting access to the file - but the problem is I have to parse and load the file as an object into memory with JSON.parse() at some point, which means anyone could inspect the object to reveal spoilers about content. Is there a way I can access just a section of the file given say, an id number, so that the entire contents aren't revealed in some way?
|
|
# ? Apr 27, 2014 19:41 |
|
The only way you can not tell people about a thing is to not tell them about it. That means having the server have some ability to not tell them about it.
|
# ? Apr 27, 2014 20:07 |
|
Suspicious Dish posted:The only way you can not tell people about a thing is to not tell them about it. That means having the server have some ability to not tell them about it. Yeah, if it's client side, we will find it and give ourselves infinite lollipops. But that's okay.
|
# ? Apr 27, 2014 21:34 |
|
I'm trying to figure out a good way to get the values of everything under a certain "branch" level in a Javascript object. I have this object:JavaScript code:
Anyway, I tried making this function (slightly different, sorry about that) in jQuery: code:
Sorry if this doesn't make a whole lot of sense, I'm surprisingly inept at Javascript.
|
# ? Apr 27, 2014 22:00 |
|
Pollyanna posted:I'm trying to figure out a good way to get the values of everything under a certain "branch" level in a Javascript object. I have this object: I think you will have to post the actual function and not some work-alike, as well as the actual data you're using. Or at least some actual runnable code and data that reproduces your problem. Your examples are a bit too vague. My guess is that your javascript object doesn't have the structure what you expect it to be.
|
# ? Apr 28, 2014 00:32 |
|
Wheany posted:I think you will have to post the actual function and not some work-alike, as well as the actual data you're using. Or at least some actual runnable code and data that reproduces your problem. Your examples are a bit too vague. Sorry. Here's a JSFiddle of exactly what I'm doing: http://jsfiddle.net/PUaHT/8/ (It outputs some debugging data into the console right now, sorry about that.) I made two functions for traversing through the first and second branches, which currently have a big-O factor of "pathetic". I'm wondering if there's some changes to the data structure I can make to change that...
|
# ? Apr 28, 2014 01:12 |
|
Pollyanna posted:Sorry. Here's a JSFiddle of exactly what I'm doing: I'm still not sure what exactly you are trying to do, but maybe this? I added underscore.js as an external resource and I use reduce and isObject functions from it. http://jsfiddle.net/PUaHT/14/ Here is the relevant snippet: JavaScript code:
If you want to access the value of a single skill, just use the dot notation: char_skills.social.royal_demeanor.composure If you want to access the value of a single skill and you don't know where in the tree it is, then you will have to search for it and performance will be poo poo.
|
# ? Apr 28, 2014 09:25 |
|
I need to create a page that presents a lot of tabular data; Basically, a CSV file with several hundred thousand entries. I'd like the user to be able to filter, search, etc. I haven't done anything in this style before, and I'm wondering if there are any frameworks or libraries made for this sort of thing to make my life easier. Can anyone point me in the right direction?
|
# ? Apr 28, 2014 21:36 |
|
Geisladisk posted:I need to create a page that presents a lot of tabular data; Basically, a CSV file with several hundred thousand entries. I'd like the user to be able to filter, search, etc. I haven't done anything in this style before, and I'm wondering if there are any frameworks or libraries made for this sort of thing to make my life easier. Can anyone point me in the right direction? Datatables is really awesome and will probably work well: https://datatables.net/ However I don't know how well it would handle tons of data. It does have ajax loading if you do have tons of data, but that's more server side effort.
|
# ? Apr 28, 2014 21:53 |
|
Several hundred thousand records is gonna be chunky no matter how you dice it, unless you're displaying a portion at a time and using asynchronous storage to retrieve it (websql or indexeddb). Datatables will do what you want but the size of the array will be an issue.
|
# ? Apr 29, 2014 05:08 |
|
Crossfilter is fast if your data fits it.
|
# ? Apr 29, 2014 06:59 |
|
I'm new to JS. Does anyone have experience with the gmaps API? Is there a way to automatically check and uncheck form checkboxes after the page is mostly finished loading? I have a gmaps API page with various overlay, such as polygons, polylines and symbols. Each has an associated text label, made using a custom overlay I adapted from the answer to this Stack Overflow post The overlays are stored as an object called 'overlays' with layout 'description: [polyline, customoverlaylabel]' Checkbox example code: HTML code:
JavaScript code:
JavaScript code:
Here's the hide method of the custom text overlay: JavaScript code:
Here's what the bulk of the custom overlay code looks like, for reference. I don't really understand it: JavaScript code:
Dominoes fucked around with this message at 11:41 on Apr 29, 2014 |
# ? Apr 29, 2014 10:51 |
|
Wheany posted:I'm still not sure what exactly you are trying to do, but maybe this? I added underscore.js as an external resource and I use reduce and isObject functions from it. I figured it out using jQuery. JSFiddle here, but the question now is if the way I made the data structure will play nice with React Cause I don't wanna have to make components for each subset of data when the entire point of frameworks like this is modularity and sticking to DRY principles.
|
# ? May 1, 2014 05:19 |
|
I have a (probably retarded) knockout question. I'm trying to get hip with the times and make my web apps more snappy and nice by doing client side binding and moving more towards Single Page Applications and whatnot. Problem is I'm very bad at javascript, apparently. I have a search that I want to use knockout with, in the following way. Tell me if there are any glaring errors: JavaScript code:
HTML code:
code:
|
# ? May 2, 2014 21:28 |
|
Pretty sure you have to make resultsArray an observable array.
|
# ? May 2, 2014 21:33 |
|
I'm skimming over some slides on JS basics, which I'm pretty familiar with already, just making sure I'm not missing anything. There's one concept that he keeps going back to that's kind of confusing to me: treating arrays and function as objects like this:code:
code:
|
# ? May 3, 2014 00:14 |
|
Fish Ladder Theory posted:I'm skimming over some slides on JS basics, which I'm pretty familiar with already, just making sure I'm not missing anything. There's one concept that he keeps going back to that's kind of confusing to me: treating arrays and function as objects like this: "It depends", but for all intents and purposes, you'd always use a plain object. My guess is that the person is trying to reinforce the "everything is an object"-ness of javascript.
|
# ? May 3, 2014 02:06 |
|
Seems bad for arrays but for functions I could see it in node where you set a property as a subclass of the main constructor/function
|
# ? May 3, 2014 03:17 |
|
Chill Callahan posted:Pretty sure you have to make resultsArray an observable array. This didn't help. Array is still coming back but not populating the table.
|
# ? May 5, 2014 13:09 |
|
aBagorn posted:This didn't help. Array is still coming back but not populating the table. You have to add stuff to the observable array, not replace it. JavaScript code:
|
# ? May 5, 2014 19:10 |
|
Are you actually inserting the results into the observable array? You can't docode:
code:
http://jsfiddle.net/8rgxW/1/ edit: welp, beaten
|
# ? May 5, 2014 19:12 |
|
I have a question about setting cookies - does anyone know if it's even possible to cookie a user so that he's rendered a different domain's site in a no-mobile (desktop) state? Like, for instance - set the cookie on page load on a http://adserver.company.com location that links users to http://www.company.com but tell them to only be served the desktop site when they get there, regardless of device? (our mobile team shat the bed and forgot a pretty major feature in their product, so in the rush to not play the blame game they're dumping all the work on my group who doesn't normally write cookies.) I can't seem to find googled consensus that you can go cross-domain like this reliably, and being pretty unfamiliar with cookies I'm not even sure where to start attempting and I'd rather skip the fun of trying if it's not even doable. *I am not 100% sure that http://adserver.company.com is a fully a 'subdomain' of http://www.company.com, so that further muddies my searching.* This is what I'm using and it's working on my http://adserver.company.com pages, showing up as set with the correct value and expiry date, but as soon as the user moves on to the http://www.company.com pages, it's lost (and they get the broken mobile site.) code:
|
# ? May 6, 2014 01:31 |
adserver.company.com and www.company.com are both subdomains of company.com so you don't have to worry about cross-domain anything (which is good because cross-domain cookies do no exist). Take a look at the domain attribute of the cookie string. You'll want to specify domain=.company.com so the cookie can be used by all subdomains of company.com.
|
|
# ? May 6, 2014 01:44 |
|
Munkeymon posted:You have to add stuff to the observable array, not replace it. Vicar posted:Are you actually inserting the results into the observable array? You can't do You guys are awesome, thanks! Now I'm off to figure out how to 'paginate' the table that comes back with a quasi-infinite scrolling function
|
# ? May 6, 2014 13:31 |
|
fletcher posted:adserver.company.com and https://www.company.com are both subdomains of company.com so you don't have to worry about cross-domain anything (which is good because cross-domain cookies do no exist). Thanks... read through that and it made sense but I'm still not having any luck making the domain definition work correctly, I still haven't ruled out the fact that our redirect process is dropping out the cookie even if I DO have it set correctly here. F'n mobile team.
|
# ? May 6, 2014 20:09 |
|
I'm new to javascript/jquery and this one is tough to google when i do this: var foo = $(selector); afterwards, what's the difference between foo and $(foo) ? I'm noticing some jquery functions work on either and some only work on $(foo).
|
# ? May 8, 2014 20:48 |
foo is a jQuery object, and $(foo) is a jQuery object with a jQuery object as the argument (instead of a selector string): http://jsfiddle.net/eLP9p/2/ o.m. 94 fucked around with this message at 21:35 on May 8, 2014 |
|
# ? May 8, 2014 21:20 |
|
StateOwned posted:I'm new to javascript/jquery and this one is tough to google Read the API docs, they're actually pretty good: http://api.jquery.com/jQuery/ Once you have a jQuery object (which is what foo should be in your case), you should not need to pass it into $ again. Doing so will create a clone of the jQuery object, as the link above explains.
|
# ? May 8, 2014 21:27 |
|
Another day, another stupid knockout question from me: When I change my viewModel from an object literal to a function, it no longer works. For example, if I call this JavaScript code:
JavaScript code:
What am I doing wrong in the second part. I changed nothing else about the application, I just called ApplyGeneralViewModel() rather than GetIncidentGeneralInfo(). This is what the console comes up with: code:
2nd edit: when I hit the savetoServer function and call self.initializeData, it's giving me an "undefined is not a function" error at the self.Incident(data.Incident) line aBagorn fucked around with this message at 20:14 on May 9, 2014 |
# ? May 9, 2014 17:53 |
|
I have a textfile with lines like this: (about 65000 lines, 6 columns) 1 0.500 -89.500 725.330 88.743 -66.551 2 1.500 -89.500 725.359 88.744 -66.543 ... 64799 358.500 89.500 800.325 271.256 66.543 64800 359.500 89.500 800.370 271.257 66.551 What I need to do is read that text file and then do a search for the line that closely matches the numbers in the 2nd and 3rd columns. I don't know much javascript, so apologies for that. (I did this in php with a preg_split. Is there something like that in javascript?) Is it faster if I put each line in an array like this and then search thru those arrays? arrayLine 0 (1, 0.500, -89.500, 725.330, 88.743, -66.551) arrayLine 1 (2, 1.500, -89.500, 725.359, 88.744, -66.543) Currently, all I have is the reading of the text file into a variable. Any point in the right direction would help.
|
# ? May 9, 2014 18:28 |
|
stoops posted:I did this in php with a preg_split. Is there something like that in javascript? Not sure how to answer the rest of your question from the top of my head, but here's a start on that string split: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split Javascript splits strings with either another string or regex from the same method. It's really nice.
|
# ? May 9, 2014 18:45 |
|
|
# ? Jun 5, 2024 05:49 |
|
Yeah, go with what rt4 said and split the entire huge variable on linefeedsJavaScript code:
Something like this (untested and probably mathematically wrong for your data): JavaScript code:
e: copied a line but forgot to change the variables in it. obstipator fucked around with this message at 22:07 on May 9, 2014 |
# ? May 9, 2014 19:20 |