#Java performance Tip: `parallelStream()` is way slower than regular `stream()` on small amount of data. I have created a simple benchmark and run it on my 8-CPU laptop. The difference is 160x for some cases. 😲
Details 🧵 👇
👷The setup is to run the same code for streams of 10, 1000, 10_000, 100_000, and 1000_000 items long in standard and parallel modes: list.stream()
.filter(i -> i == -1)
.findAny()
.orElse(0);
Are you wondering why it is so?
When running a parallel stream, the code starts multiple threads and splits data across them. Starting threads is not a very cheap operation; therefore, on smaller streams, parallel processing is slower than gains from multi-threading.
Note, that stream sizes where classical/parallel performs better should not be taken as is to your code. These numbers depend a lot on:
- CPU
- complexity of operations your stream performs
@spolsky This law states that abstractions, which are generally used in computing to simplify working with complicated systems, will in certain situations 'leak' elements of the underlying system, this making the abstraction behave in an unexpected way.
@spolsky An example might be loading a file and reading its contents. The file system APIs are an abstraction of the lower level kernel systems, which are themselves an abstraction over the physical processes relating to changing data on a magnetic platter (or flash memory for an SSD).
#Java performance Tip: When need to copy items from one array to anoyther one, don't use loops. Use the more efficient Arrays.copyOf or System.arraycopy method instead.
⚠️Thread alert! ⚠️
Relational databases are still the most popular data storage for various projects. Here are some tips on how to scale relational databases to support more throughput, serve more clients, or get faster query processing. 🧵:
1. Update the version
Newer versions of traditional SQL databases typically come with performance improvements. Even if the newer database system is not faster as a direct replacement, there might be new features available that we can take advantage of.
2. Indexing
Properly indexing the database can significantly improve query performance and reduce the load on the database. Be sure to index columns that are used for FK joins or that are frequently searched or sorted.
Functional correctness of software is essential, but Non-Functional Requirements (NFRs) are usually forgotten during development. Here are the top 10 crucial NFRs you should care about 🧵 👇
1. Performance
Focuses on the system's speed, efficiency, and workload. It covers how fast the system should process requests and respond to them.
2. Scalability
Can the system respond to changes in demand? How will the system pull on additional resources to handle the additional load?
👮🏼♀️ FBI: "Cyber Criminals Impersonating Brands Using Search Engine Advertisement Services to Defraud Users"
The FBI recommends individuals take the following precautions: 🧵👇
📍Before clicking on an advertisement, check the URL to make sure the site is authentic. A malicious domain name may be similar to the intended URL but with typos or a misplaced letter.
📍Rather than search for a business or financial institution, type the business’s URL into an internet browser’s address bar to access the official website directly.
Top 6 free @intellijidea plugins you don't want to miss. 🧵 👇
Key Promoter X - The Key Promoter X helps you learn essential shortcuts while working. When you use the mouse on a button inside the IDE, the Key Promoter X shows you the keyboard shortcut you should have used instead.