Tag Info

New answers tagged

0

Considering as Javascript is single-threaded, there is no use in keeping an array of multiple instances, since there can only be one Transform object in use at a given time. Furthermore, since your usage of the tranform object is synchronous, there is no need to lock/free the instance. So in effect, you only need one instance, which can be made global, ...


0

You should cache the query by the query parameters. In this case user id. However, the point of caching is to prevent running the same query multiple times in quick sucession. This would usualy be caused by each user running the same query per request. When you have 1000 users on the site and each making requests at the same time and running a getMenu ...


0

Some may not feel this is not an answer, but it is a way to derive a better answer. Collect data on user behavior. Many users may prefer a default configuration. If so, it would make sense to cache this list. I've seen some apps that are highly configurable, but I just use it the way it came out of the box. I'm sure there are hundreds of settings for ...


2

I've had this exact situation come up with a co-worker and when reviewing code from contractors -- the code should always convey your intent and expectations as clearly as possible given the constraints of performance and size. Performance with SQL relies upon the query optimizer -- while it probably won't make any difference, if it does, more likely than ...


3

After fidgeting around with the code a bit, I've got some better results. I went back to the original paper and ignored the wikipedia page. I've compared the algorithm to other quick select routines with some great results. Ok, here are the methods I have been playing with. Note these are for floating point and also that I changed my method from a void. ...


2

You can split any code into pieces consisting of a linear sequence of steps that are separated by control flow changes (branches, function calls, returns, etc). To do JIT compiling, you'd start immediately after a change in control flow, scan ahead until you find the next control flow change, convert the linear sequence of steps into native code, optimise ...


1

This question is too broad; there are too many factors that could contribute to the fluctuations in the time taken to execute some source code. The poorly-written question also doesn't help - it is unclear whether the asker is more interested in knowing the possible factors that affect nanoscopic performance (on the order of 1 - 10 CPU instructions) or ...


2

Modern CPUs don't do one instruction at a time. Instead, they might be decoding one group of instructions while an earlier group are waiting for dependencies and waiting to be sent to execution units, while even earlier instructions are being executed, while even earlier instructions are being retired (committed to state). It's (literally) a pipeline of ...


0

As I was clearing up the description, a potential third option (Redesigned java class) dawned on me. So I am going to investigate it further as it looks promising with no model impact. Let me know if this is not a good option based on the use case and if you see any issues with it.


0

It depends on what you intend to do with the content of the files. If you ever need to make queries based on the content of the sheets (and I am pretty sure you will have to), I really think you should consider the table solution. I think there are some ways to improve your performance issues (batch insert...).


0

Perhaps consider a hybrid approach. Fetching and storing documents is the purview of document-centric or "NoSQL" databases. Perhaps store the actual spreadsheets in (e.g.) Cassandra and keep your metadata (and copies of any working data, if you only really care about a subset of the data in the spreadsheet) in Oracle. As to your memory pressure in Tomcat, ...


2

Yes, the big question is what do you want to do with these excel documents once they're in the DB. You can store them as BLOBS quite happily, but then you can store them as files on the filesystem too, and the latter allows you to manipulate the documents in various ways (eg running code to change them). If you're just storing them for later retrieval, ...


4

The challenge is how should this information be stored efficiently in an RDBMS? The question should be why should this information be stored in a RDBMS at all? What are you going to do with it once it's there? If all you're going to do is "save" a spreadsheet into the database and then pull it back out again, then I'd suggest you're wasting your ...


0

Your description of the home page seems like a dashboard page. The best practice for powering a dashboard page is to allow the data to be populated with queries that are executed in parallel. This allows any bad performing queries to be tuned independently. This also makes it easier to add a new data view if needed when the home page evolves. If all the ...


0

Generally speaking, it is not good to duplicate values unless there is a valid reason. For the above solution, it is definitely not a good idea. Though it might seem counter-intuitive, ORMs by default (Hibernate) prefer to load and save all the fields of an entity (recommended upto a limit ~50 columns). The main reason is that they can pre-build these SQLs ...


0

What type of problem are you trying to solve? Are all the 100000 records related to each other so that everything needs to be loaded in memory. If not, try to find a suitable grouping (e.g., customer). Reformulate the problem that handles each group separately and after that group of records are processed, flush the data to the CSV file and clear the memory ...


4

Iterating through a List is (slightly) slower than a plain array due to a few factors: Bounds checks: This is likely to be the biggest factor; every single indexer access to the List is going to do a bounds check. Bounds checking on a raw array can often be trivially optimized out of a loop by the JIT. Method call costs: The indexer on a List is a method ...


0

One argument I'm missing here is the possibility of increased protection against cross site scripting attacks. It's possible to disable the execution of inline JavaScript in modern browser via the Content Security Policy. This reduced the risk of your site falling victim of XSS. This may be a more convincing argument to make to your management to invest in ...


0

One reason NOT to use InLine Javascript (not even onclick="DoThis(this)" on buttons), is if you intend to make your web application a Chrome App. So, if you are planning to port your web app into a Native Chrome App, start by NOT including ANY inline javascript. This is explained right at the beginning of what you will need to change (mandatorily) from your ...


0

I think it would be rare in practice to actually have the option. The decision will likely be made for you simply by the requirements of the application. The semantics of your two examples are very different. It's a typical by-value or by-reference decision. I think you just need to ask Content myContent; myContent.Value = "Some content"; Node myNode; ...


6

Java streams do not iterate through your collection once for each statement, despite what the syntax implies. It applies the entire chain to each element, one element at a time. In your case, the stream would operate exactly like the loop. Take an element, check it against your predicate, and then apply your operation, then move on to the next element.


8

Nearly all CPUs have a single instruction that will return the modulus of a value. For instance, consider this program: int main() { int i = 10; return i % 3; } If I compile this on my Intel OS X machine using g++ -S, the result will be some boilerplate and this: movl $3, %eax movl $0, -4(%rbp) movl $10, -8(%rbp) movl -8(%rbp), %ecx ...


2

I've been faced with this, and the answer is: For someone experienced in performance tuning, the new code can be tuned so almost no code can go faster. Here's an example. The reason is, there is a minimum length of time the task can take, and it's greater than one cycle. There are many, many programs that can do the task, and one or more of them take less ...


7

and don't want to ask the individuals doing the work to manually record things like how long it takes them to perform a given task Here's the problem. You basically want to create meaningful metrics, without measuring the only thing that matters. Nearly all of your users won't care about how fast the code itself is unless it causes a noticeable impact ...


3

Generally if you push more code to DB and if you do it right, it should result in performance increase. And I don't see why the interviewer claim its other way round. Personally I would not put any code into DB simply due to ease of maintenance and ease of unit testing. In most of the applications performance improvement due to moving logic into DB does not ...


2

The main reason for not having code in the database is testability and maintenance. It is relatively hard to test the database code and it is a kind of hidden logic, which will become hard to maintain as you logic is spread all over and regress especially in the maintenance phase of your project.


10

Performance does neither increase or decrease because "you put most of the code into database" or because "you keep the code out of the database". The key point is to put the right parts of the code into the database (or to keep them out). Parts which helps to reduce the network traffic might be a good fit for stored procedures. Parts which do heavy ...


3

This answer is specific to C++ (as indicated by the tag on this question). Most other compiled languages (outside C and C++) do not have such consideration, because in those languages there is no benefit in moving configurations to compile-time. Outside of C and C++, conditional compilation is greatly discouraged or simply unsupported. Also, C and C++ ...


1

The title hints that the topic is somewhat opinion-based. However, let's ignore this issue and address the question. I think the pros and cons are fairly obvious, since both methods are just trade offs. For example, let's say you've implemented a runtime configuration-system. Cons: What do you do if some values are missing in the config / the config ...


1

Your decision whether to have code-based configuration or file-based configuration will depend entirely on whether or not you need the flexibility of configuring at runtime vs. compile time. Performance is almost certainly a non-issue, since you can cache the values once they are read from the configuration file.


1

See http://stackoverflow.com/q/5527437/10396 for an implementation of a rolling median that uses a min-max heap to process each new sample in O(lgN). The heap keeps the data loosely sorted into two groups, one bigger than the median, one smaller. For each new sample, it swaps the the oldest item in the heap with the newest one. Rebalancing the heap takes ...


1

My suggestion would be to slurp the large list into a hash set, then use that to match items from the small list. A hash set is a structure that stores elements in an indexable memory structure, like an array, where the position of the element is equal to some hash value calculated using the object. That means that looking for a value in the hashset is a ...


2

Sort both lists with an efficient sorting algorithm (or ensure that the lists are "pre-sorted" by whoever/whatever created them). Then, if the first name in both lists is the same you've found a match, otherwise discard whichever name is "earlier"; and do that until one of the lists are empty. Some crude pseudo-code: do { status = ...


2

Sort the small list with an efficient sorting algorithm, traverse the big list and for every item in the big list use a binary search to find whether there's a matching item in the small list.


0

Finding things in one set that match those in another set and merging data is something that relational databases excel at. If this is something you need to do a lot, loading your lists into tables in your choice of SQL DB is probably your best option.



Top 50 recent answers are included